bool WAbstractToggleButton::supportsIndeterminate(const WEnvironment& env)
  const
{
  return env.javaScript()
    && (env.agentIsIE()
	|| env.agentIsSafari()
	|| (env.agentIsGecko() && (env.agent() >= WEnvironment::Firefox3_6)));
}
Пример #2
0
ChatWidget::ChatWidget(const WEnvironment& env, SimpleChatServer& server)
  : WApplication(env),
    login_(this, "login")
{
  setCssTheme("");
  useStyleSheet("chatwidget.css");
  useStyleSheet("chatwidget_ie6.css", "lt IE 7");

  const std::string *div = env.getParameter("div");
  std::string defaultDiv = "div";
  if (!div)
   div = &defaultDiv;

  if (div) {
    setJavaScriptClass(*div);
    PopupChatWidget *chatWidget = new PopupChatWidget(server, *div);
    bindWidget(chatWidget, *div);

    login_.connect(chatWidget, &PopupChatWidget::setName);

    std::string chat = javaScriptClass();
    doJavaScript("if (window." + chat + "User) "
		 + chat + ".emit(" + chat + ", 'login', " + chat + "User);"
		 + "document.body.appendChild(" + chatWidget->jsRef() + ");");
  } else {
    std::cerr << "Missing: parameter: 'div'" << std::endl;
    quit();
  }
}
Пример #3
0
  AuthApplication(const WEnvironment& env)
    : WApplication(env),
      session_(appRoot() + "auth.db")
  {
    session_.login().changed().connect(this, &AuthApplication::authEvent);

    useStyleSheet("css/style.css");

    std::unique_ptr<Auth::AuthWidget> authWidget(new Auth::AuthWidget(
                          Session::auth(), session_.users(), session_.login()));

    authWidget->setRegistrationEnabled(true);

    WSslInfo *sslInfo = env.sslInfo();
    if (sslInfo) {
      Auth::Identity id = createIdentity(sslInfo);
      Auth::User u = session_.users().findWithIdentity(id.provider(),
							   id.id());
      if (!u.isValid()) 
	authWidget->registerNewUser(id);
      else
        session_.login().login(u, Auth::LoginState::Weak);

      root()->addWidget(std::move(authWidget));
    } else {
      root()->addWidget(cpp14::make_unique<WText>("Not an SSL session, or no "
          "client certificate available. Please read the readme file in "
          "examples/feature/client-ssl-auth for more info."));
      quit();
    }

  }
Пример #4
0
HelloApplication::HelloApplication(const WEnvironment& env, bool embedded)
  : WApplication(env)
{
  WContainerWidget *top;

  setTitle("Hello world");

  if (!embedded) {
    /*
     * In Application mode, we have the root() is a container
     * corresponding to the entire browser window
     */
    top = root();

  } else {
    /*
     * In WidgetSet mode, we create and bind containers to existing
     * divs in the web page. In this example, we create a single div
     * whose DOM id was passed as a request argument.
     */

      std::unique_ptr<WContainerWidget> topPtr
          = cpp14::make_unique<WContainerWidget>();
      top = topPtr.get();

      const std::string *div = env.getParameter("div");
      if (div) {
          setJavaScriptClass(*div);
          bindWidget(std::move(topPtr), *div);
      } else {
          std::cerr << "Missing: parameter: 'div'" << std::endl;
          return;
      }
  }


  if (!embedded)
    root()->addWidget(cpp14::make_unique<WText>(
       "<p><emph>Note: you can also run this application "
       "from within <a href=\"hello.html\">a web page</a>.</emph></p>"));

  /*
   * Everything else is business as usual.
   */

  top->addWidget(cpp14::make_unique<WText>("Your name, please ? "));
  nameEdit_ = top->addWidget(cpp14::make_unique<WLineEdit>());
  nameEdit_->setFocus();

  auto b = top->addWidget(cpp14::make_unique<WPushButton>("Greet me."));
  b->setMargin(5, Side::Left);

  top->addWidget(cpp14::make_unique<WBreak>());

  greeting_ = top->addWidget(cpp14::make_unique<WText>());

  /*
   * Connect signals with slots
   */
  b->clicked().connect(this, &HelloApplication::greet);
  nameEdit_->enterPressed().connect(this, &HelloApplication::greet);
}
CgiRoot::CgiRoot(const WEnvironment &env)
    : WApplication(env),
      m_pimpl(make_unique<CgiRoot::Impl>(this))
{
    try {
        this->setInternalPathDefaultValid(false);

        WBootstrapTheme *bootstrapTheme = new WBootstrapTheme();
        bootstrapTheme->setVersion(WBootstrapTheme::Version3);
        bootstrapTheme->setResponsive(true);
        bootstrapTheme->setFormControlStyleEnabled(true);
        setTheme(bootstrapTheme);

        CgiEnv *cgiEnv = this->GetCgiEnvInstance();

        if (cgiEnv->FoundXSS())
            throw Service::Exception(ALICE);

        root()->clear();

        switch (cgiEnv->GetCurrentLanguage()) {
        case CgiEnv::Language::None:
        case CgiEnv::Language::Invalid:
            try {
                m_pimpl->ReloadWithLanguage(env.getCookie("lang"));
            } catch (...) {
                if (algorithm::contains(
                            cgiEnv->GetClientInfo(CgiEnv::ClientInfo::Location),
                            "Iran")
                        || algorithm::starts_with(locale().name(), "fa")) {
                    m_pimpl->ReloadWithLanguage("fa");
                } else {
                    m_pimpl->ReloadWithLanguage("en");
                }
            }
            return;

        case CgiEnv::Language::En:
        case CgiEnv::Language::Fa:
            if (env.supportsCookies()) {
                setCookie("lang", cgiEnv->GetCurrentLanguageString(),
                          Pool::Storage()->LanguageCookieLifespan());
            }
        }

        setLocale(cgiEnv->GetCurrentLanguageString());
        messageResourceBundle().use(appRoot() + "../i18n/localization");

        if (cgiEnv->GetCurrentLanguageDirection() == CgiEnv::LanguageDirection::RightToLeft) {
            setLayoutDirection(Wt::LayoutDirection::RightToLeft);
        }

        if (!cgiEnv->IsRootLoginRequested()) {
            root()->addWidget(m_pimpl->GetHomePage());
        } else {
            root()->addWidget(m_pimpl->GetRootLoginPage());
        }
    }

    catch (const Service::Exception &ex) {
        root()->clear();
        root()->addWidget(new WText(ex.What()));
    }

    catch (const CoreLib::Exception &ex) {
        LOG_ERROR(ex.what());
    }

    catch (...) {
        LOG_ERROR(UNKNOWN_ERROR);
    }
}