Example #1
0
void WPopupWidget::defineJS()
{
    WApplication *app = WApplication::instance();

    LOAD_JAVASCRIPT(app, "js/WPopupWidget.js", "WPopupWidget", wtjs1);

    WStringStream jsObj;

    jsObj << "new " WT_CLASS ".WPopupWidget("
          << app->javaScriptClass() << ',' << jsRef() << ','
          << transient_ << ',' << autoHideDelay_ << ','
          << !isHidden() << ");";

    setJavaScriptMember(" WPopupWidget", jsObj.str());
}
Example #2
0
void WAbstractSpinBox::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/WSpinBox.js", "WSpinBox", wtjs1);

  std::string jsObj = "new " WT_CLASS ".WSpinBox("
    + app->javaScriptClass() + "," + jsRef() + ","
    + boost::lexical_cast<std::string>(decimals()) + ","
    + prefix().jsStringLiteral() + ","
    + suffix().jsStringLiteral() + ","
    + jsMinMaxStep() + ");";

  setJavaScriptMember("_a", "0;" + jsObj);
}
Example #3
0
void WSuggestionPopup::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  const char *THIS_JS = "js/WSuggestionPopup.js";
  LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopup", wtjs1);
  LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopupStdMatcher", wtjs2);

  setJavaScriptMember(" WSuggestionPopup",
		      "new " WT_CLASS ".WSuggestionPopup("
		      + app->javaScriptClass() + "," + jsRef() + ","
		      + replacerJS_ + "," + matcherJS_ + ","
		      + boost::lexical_cast<std::string>(filterLength_) + ","
		      + boost::lexical_cast<std::string>(defaultValue_) + ");");
}
Example #4
0
/**
* @brief Get's the cookie from the app
*
* @return The cookie that the client's browser is giving us
*/
const string& BaseSessionHandle::getCookie() const {
    // First ask the browser
    WApplication* app = WApplication::instance();
    const WEnvironment::CookieMap& cookies = app->environment().cookies();
    WEnvironment::CookieMap::const_iterator i = cookies.find(_cookieName);
    if (i != cookies.end()) {
        return (*i).second;
    }
    // Fall back to cached version
    // If the browser doesn't have a cookie, we might have just set it and no requests have happened yet
    // Even if this server side cache is old (and the user has logged out, and the client side cookie deleted)
    // It shouldn't matter because the session store still won't return a user ID for it.
    // But still if there is a browser side cookie, that takes precedence
    return cookieCache;
}
Example #5
0
void WMenu::undoSelectVisual()
{
  std::string prevPath = previousInternalPath_;
  int prevStackIndex = previousStackIndex_;

  selectVisual(current_, true, true);

  if (internalPathEnabled_) {
    WApplication *app = wApp;
    app->setInternalPath(prevPath);
  }

  if (contentsStack_)
    contentsStack_->setCurrentIndex(prevStackIndex);
}
Example #6
0
void WMenuItem::setIcon(const std::string& path)
{
  if (!icon_) {
    WAnchor *a = anchor();
    if (!a)
      return;

    icon_ = new WText(" ");
    a->insertWidget(0, icon_);

    WApplication *app = WApplication::instance();
    app->theme()->apply(this, icon_, MenuItemIconRole);
  }

  icon_->decorationStyle().setBackgroundImage(WLink(path));
}
Example #7
0
void WMenuItem::setCloseable(bool closeable)
{
  if (closeable_ != closeable) {
    closeable_ = closeable;

    if (closeable_) {
      WText *closeIcon = new WText("");
      insertWidget(0, std::unique_ptr<WText>(closeIcon));
      WApplication *app = WApplication::instance();
      app->theme()->apply(this, closeIcon, WidgetThemeRole::MenuItemClose);

      closeIcon->clicked().connect(this, &WMenuItem::close);
    } else
      removeWidget(widget(0));
  }
}
Example #8
0
void AuthModel::logout(Login& login)
{
  if (login.loggedIn()) {
    if (baseAuth()->authTokensEnabled()) {
      WApplication *app = WApplication::instance();
      app->removeCookie(baseAuth()->authTokenCookieName());

      /*
       * FIXME: it would be nice if we also delete the relevant token
       * from the database!
       */
    }

    login.logout();
  }
}
Example #9
0
void AuthWidget::init()
{
    registrationModel_ = 0;
    registrationEnabled_ = false;
    created_ = false;
    dialog_ = 0;
    messageBox_ = 0;

    addFunction("id", WT_TEMPLATE_FUNCTION(id));
    addFunction("tr", WT_TEMPLATE_FUNCTION(tr));

    WApplication *app = WApplication::instance();
    app->useStyleSheet(WApplication::resourcesUrl() + "form.css");
    app->internalPathChanged().connect(this, &AuthWidget::onPathChange);
    app->builtinLocalizedStrings().useBuiltin(skeletons::Auth_xml1);
}
Example #10
0
void WsNewsLetter::sendConfirmMail(const std::string& email,
                                       const std::string& userToken) const
{
  std::string url = "/newsletter/subscribe/";
  WApplication *app = WApplication::instance();
  url = app->makeAbsoluteUrl(app->bookmarkUrl(url)) + userToken;

  Mail::Message message;

  message.addRecipient(Mail::To, Mail::Mailbox(email));
  message.setSubject(WString::tr("subject"));
  message.setBody(WString::tr("body").arg(email).arg(url));
  message.addHtmlBody(WString::tr("htmlbody").arg(email).arg(url));

  sendMail(message);
}
Example #11
0
void WTextEdit::init()
{
  WApplication *app = WApplication::instance();

  setInline(false);

  initTinyMCE();

  version_ = getTinyMCEVersion();

  setJavaScriptMember(" WTextEdit", "new " WT_CLASS ".WTextEdit("
		      + app->javaScriptClass() + "," + jsRef() + ");");

  setJavaScriptMember
    (WT_RESIZE_JS,
     "function(e, w, h) { var obj = $('#" + id() + "').data('obj'); "
     "obj.wtResize(e, w, h); };");

  std::string direction = app->layoutDirection() == LeftToRight ? "ltr" : "rtl";
  setConfigurationSetting("directionality", direction);

  std::string toolbar;
  if (version_ < 4)
    toolbar = "fontselect,|,bold,italic,underline,|,fontsizeselect,|"
      ",forecolor,backcolor,|"
      ",justifyleft,justifycenter,justifyright,justifyfull,|,anchor,|"
      ",numlist,bullist";
  else
    toolbar = "undo redo | styleselect | bold italic | link";

  setToolBar(0, toolbar);
  for (int i = 1; i <= 3; i++)
    setToolBar(i, std::string());

  setConfigurationSetting("doctype", wApp->docType());
  setConfigurationSetting("relative_urls", true);

  if (version_ < 4) {
    //this setting is no longer mentioned in the tinymce documenation though...
    setConfigurationSetting("button_tile_map", true);
    setConfigurationSetting("theme", std::string("advanced"));
    setConfigurationSetting("theme_advanced_toolbar_location", 
			    std::string("top"));
    setConfigurationSetting("theme_advanced_toolbar_align",
			    std::string("left"));
  }
}
Example #12
0
void menuWidget::gameStarted()
{
    WApplication * app = WApplication::instance();
    gameEnded = false;
    if(ifCreator)
    {
        information->setText("It's your turn");
    }
    endGame->disable();
    giveUp->enable();
    map<Coordinates,WPushButton*>::iterator it;
    for(it = gameButtons.begin(); it != gameButtons.end(); it++)
    {
        it->second->enable();
    }
    app->triggerUpdate();
}
Example #13
0
bool AuthWidget::handleRegistrationPath(const std::string& path)
{
  if (!basePath_.empty()) {
    WApplication *app = WApplication::instance();

    if (app->internalPathMatches(basePath_)) {
      std::string ap = app->internalSubPath(basePath_);

      if (ap == "register") {
	registerNewUser();
	return true;
      }
    }
  }

  return false;
}
Example #14
0
void WMenuItem::setCloseable(bool closeable)
{
  if (closeable_ != closeable) {
    closeable_ = closeable;

    if (closeable_) {
      WText *closeIcon = new WText("");
      insertWidget(0, closeIcon);
      WApplication *app = WApplication::instance();
      app->theme()->apply(this, closeIcon, MenuItemCloseRole);

      closeIcon->clicked().connect(this, &WMenuItem::close);
    } else {
      delete widget(0);
    }
  }
}
Example #15
0
void WMenuItem::setCheckable(bool checkable)
{
  if (isCheckable() != checkable) {
    if (checkable) {
      checkBox_ = new WCheckBox();
      anchor()->insertWidget(0, checkBox_);
      setText(text());

      text_->setBuddy(checkBox_);

      WApplication *app = WApplication::instance();
      app->theme()->apply(this, checkBox_, MenuItemCheckBoxRole);
    } else {
      delete checkBox_;
    }
  }
}
Example #16
0
File: WMenu.C Project: LifeGo/wt
void WMenu::setInternalPathEnabled(const std::string& basePath)
{
  WApplication *app = WApplication::instance();

  basePath_ = basePath.empty() ? app->internalPath() : basePath;
  basePath_ = Utils::append(Utils::prepend(basePath_, '/'), '/');

  if (!internalPathEnabled_) {
    internalPathEnabled_ = true;
    app->internalPathChanged().connect(this, &WMenu::handleInternalPathChange);
  }

  previousInternalPath_ = app->internalPath();
  internalPathChanged(app->internalPath());

  updateItemsInternalPath();
}
Example #17
0
WMediaPlayer::WMediaPlayer(MediaType mediaType, WContainerWidget *parent)
  : WCompositeWidget(parent),
    mediaType_(mediaType),
    videoWidth_(0),
    videoHeight_(0),
    gui_(this),
    boundSignals_(0)
{
  for (unsigned i = 0; i < 11; ++i)
    control_[i] = 0;

  for (unsigned i = 0; i < 3; ++i)
    display_[i] = 0;

  for (unsigned i = 0; i < 2; ++i)
    progressBar_[i] = 0;

  WTemplate *impl = new WMediaPlayerImpl(this, tr("Wt.WMediaPlayer.template"));
  impl->bindString("gui", std::string());

  setImplementation(impl);

  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/WMediaPlayer.js", "WMediaPlayer", wtjs1);

  std::string res = WApplication::relativeResourcesUrl() + "jPlayer/";

  if (!app->environment().ajax())
    app->require(res + "jquery.min.js");

  if (app->require(res + "jquery.jplayer.min.js"))
    app->useStyleSheet(res + "skin/jplayer.blue.monday.css");

  if (mediaType_ == Video)
    setVideoSize(480, 270);

#ifndef WT_TARGET_JAVA
  implementJavaScript(&WMediaPlayer::play,
		      jsPlayerRef() + ".jPlayer('play');");
  implementJavaScript(&WMediaPlayer::pause,
		      jsPlayerRef() + ".jPlayer('pause');");
  implementJavaScript(&WMediaPlayer::stop,
		      jsPlayerRef() + ".jPlayer('stop');");
#endif
}
Example #18
0
StdGridLayoutImpl2::~StdGridLayoutImpl2()
{ 
  WApplication *app = WApplication::instance();

  /*
   * If it is a top-level layout (as opposed to a nested layout),
   * configure overflow of the container.
   */
  if (parentLayoutImpl() == 0) {
    if (container() == app->root()) {
      app->setBodyClass("");
      app->setHtmlClass("");
    }

    if (app->environment().agentIsIElt(9) && container())
      container()->setOverflow(WContainerWidget::OverflowVisible);
  }
}
Example #19
0
void WMenuItem::setCheckable(bool checkable)
{
  if (isCheckable() != checkable) {
    if (checkable) {
      std::unique_ptr<WCheckBox> cb(checkBox_ = new WCheckBox());
      anchor()->insertWidget(0, std::move(cb));
      setText(text());

      text_->setBuddy(checkBox_);

      WApplication *app = WApplication::instance();
      app->theme()->apply(this, checkBox_, WidgetThemeRole::MenuItemCheckBox);
    } else {
      removeWidget(checkBox_);
      checkBox_ = nullptr;
    }
  }
}
Example #20
0
File: WText.C Project: LifeGo/wt
std::string WText::formattedText() const
{
  if (text_.format == PlainText)
    return escapeText(text_.text, true).toUTF8();
  else {
    WApplication *app = WApplication::instance();
    if (flags_.test(BIT_ENCODE_INTERNAL_PATHS)
	|| app->session()->hasSessionIdInUrl()) {
      WFlags<RefEncoderOption> options;
      if (flags_.test(BIT_ENCODE_INTERNAL_PATHS))
	options |= EncodeInternalPaths;
      if (app->session()->hasSessionIdInUrl())
	options |= EncodeRedirectTrampoline;
      return EncodeRefs(text_.text, options).toUTF8();
    } else
      return text_.text.toUTF8();
  }
}
Example #21
0
void WFormWidget::defineJavaScript(bool force)
{
  if (force || !flags_.test(BIT_JS_OBJECT)) {
    flags_.set(BIT_JS_OBJECT);

    if (!isRendered())
      return;

    WApplication *app = WApplication::instance();

    LOAD_JAVASCRIPT(app, "js/WFormWidget.js", "WFormWidget", wtjs1);

    doJavaScript("new " WT_CLASS ".WFormWidget("
		 + app->javaScriptClass() + "," 
		 + jsRef() + ","
		 + emptyText_.jsStringLiteral() + ");");
  }
}
Example #22
0
void WDialog::setHidden(bool hidden, const WAnimation& animation)
{
  if (isHidden() != hidden) {
    if (modal_) {
      WApplication *app = WApplication::instance();
      WContainerWidget *cover = app->dialogCover();

      if (!cover)
	return; // when application is being destroyed

      if (!hidden) {
	saveCoverState(app, cover);

	if (cover->isHidden()) {
	  if (!animation.empty()) {
	    cover->animateShow(WAnimation(WAnimation::Fade, WAnimation::Linear,
					  animation.duration() * 4));
	  } else
	    cover->show();
	}

	cover->setZIndex(impl_->zIndex() - 1);
	app->pushExposedConstraint(this);

	// FIXME: this should only blur if the active element is outside
	// of the dialog
	doJavaScript
	  ("try {"
           """var ae=document.activeElement;"
           // On IE when a dialog is shown on startup, activeElement is the
           // body. Bluring the body sends the window to the background if
           // it is the only tab.
           // http://redmine.emweb.be/boards/2/topics/6415
	   """if (ae && ae.blur && ae.nodeName != 'BODY') {"
	   ""  "document.activeElement.blur();"
           "}"
	   "} catch (e) { }");
      } else
	restoreCoverState(app, cover);
    }
  }

  WPopupWidget::setHidden(hidden, animation);
}
Example #23
0
void WDialog::render(WFlags<RenderFlag> flags)
{
  if (flags & RenderFull) {
    WApplication *app = WApplication::instance();

    bool centerX = offset(Left).isAuto() && offset(Right).isAuto(),
      centerY = offset(Top).isAuto() && offset(Bottom).isAuto();

    /*
     * Make sure layout adjusts to contents preferred width, especially
     * important for IE workaround which uses static position scheme
     */
    if (app->environment().ajax())
      if (width().isAuto())
	if (maximumWidth().unit() == WLength::Percentage ||
	    maximumWidth().toPixels() == 0)
	  impl_->resolveWidget("layout")->setMaximumSize(999999, maximumHeight());

    doJavaScript("new " WT_CLASS ".WDialog("
		 + app->javaScriptClass() + "," + jsRef()
		 + "," + titleBar_->jsRef()
		 + "," + (centerX ? "1" : "0")
		 + "," + (centerY ? "1" : "0") + ");");

    /*
     * When a dialog is shown immediately for a new session, the recentering
     * logic comes too late and causes a glitch. Thus we include directly in
     * the HTML a JavaScript block to mitigate that
     */
    if (!app->environment().agentIsIElt(9)) {
      std::string js = WString::tr("Wt.WDialog.CenterJS").toUTF8();
      Utils::replace(js, "$el", "'" + id() + "'");
      Utils::replace(js, "$centerX", centerX ? "1" : "0");
      Utils::replace(js, "$centerY", centerY ? "1" : "0");

      impl_->bindString
	("center-script", "<script>" + js + "</script>", XHTMLUnsafeText);
    } else
      impl_->bindEmpty("center-script");
  }

  WCompositeWidget::render(flags);
}
Example #24
0
void WPopupMenu::done(WPopupMenuItem *result)
{
  location_ = 0;
  result_ = result;

  hide();

  WApplication *app = WApplication::instance();

  app->root()->clicked().disconnect(globalClickConnection_);
  app->globalEscapePressed().disconnect(globalEscapeConnection_);
  app->popExposedConstraint(this);

  recursiveEventLoop_ = false;

  triggered_.emit(result_);

  aboutToHide_.emit();
}
Example #25
0
void WSuggestionPopup::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  const char *THIS_JS = "js/WSuggestionPopup.js";
  LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopup", wtjs1);
  LOAD_JAVASCRIPT(app, THIS_JS, "WSuggestionPopupStdMatcher", wtjs2);

  std::string ddUnfiltered = isDropDownIconUnfiltered_ ? "true" : "false";
  setJavaScriptMember(" WSuggestionPopup",
		      "new " WT_CLASS ".WSuggestionPopup("
		      + app->javaScriptClass() + "," + jsRef() + ","
		      + replacerJS_ + "," + matcherJS_ + ","
		      + boost::lexical_cast<std::string>
		        (std::max(0, filterLength_)) + ","
		      + boost::lexical_cast<std::string>(partialResults()) + ","
                      + boost::lexical_cast<std::string>(defaultValue_) + ","
                      + ddUnfiltered + ");");
}
Example #26
0
void WAbstractSpinBox::defineJavaScript()
{
  WApplication *app = WApplication::instance();

  LOAD_JAVASCRIPT(app, "js/WSpinBox.js", "WSpinBox", wtjs1);

  WStringStream ss;

  ss << "new " WT_CLASS ".WSpinBox("
    << app->javaScriptClass() << "," << jsRef() << "," << decimals() << ","
    << prefix().jsStringLiteral() << ","
    << suffix().jsStringLiteral() << ","
    << jsMinMaxStep() << ","
    << jsStringLiteral(WLocale::currentLocale().decimalPoint()) << ","
    << jsStringLiteral(WLocale::currentLocale().groupSeparator())
    << ");";

  setJavaScriptMember(" WSpinBox", ss.str());
}
Example #27
0
File: WResource.C Project: bend/wt
const std::string& WResource::generateUrl()
{
  WApplication *app = WApplication::instance();

  if (app) {
    WebController *c = 0;
    if (trackUploadProgress_)
      c = WebSession::instance()->controller();

    if (c && !currentUrl_.empty())
      c->removeUploadProgressUrl(currentUrl_);
    currentUrl_ = app->addExposedResource(this);
    if (c)
      c->addUploadProgressUrl(currentUrl_);    
  } else
    currentUrl_ = internalPath_;

  return currentUrl_;
}
Example #28
0
void WProgressBar::updateDom(DomElement& element, bool all)
{
  DomElement *bar = 0, *label = 0;

  if (all) {
    WApplication *app = WApplication::instance();

    bar = DomElement::createNew(DomElement_DIV);
    bar->setId("bar" + id());
    bar->setProperty(PropertyClass, valueStyleClass_);
    app->theme()->apply(this, *bar, ProgressBarBarRole);

    label = DomElement::createNew(DomElement_DIV);
    label->setId("lbl" + id());
    app->theme()->apply(this, *label, ProgressBarLabelRole);
  }

  if (changed_ || all) {
    if (!bar)
      bar = DomElement::getForUpdate("bar" + id(), DomElement_DIV);
    if (!label)
      label = DomElement::getForUpdate("lbl" + id(), DomElement_DIV);

    bar->setProperty(PropertyStyleWidth,
		     boost::lexical_cast<std::string>(percentage()) + "%");

    WString s = text();
    removeScript(s);

    label->setProperty(PropertyInnerHTML, s.toUTF8());

    changed_ = false;
  }

  if (bar)
    element.addChild(bar);

  if (label)
    element.addChild(label);

  WInteractWidget::updateDom(element, all);
}
Cms::Cms()
    : Page(),
    m_pimpl(make_unique<Cms::Impl>())
{
    WApplication *app = WApplication::instance();
    app->setTitle(tr("cms-page-title"));

    this->clear();
    this->setId("CmsPage");
    this->setStyleClass("cms-page container-fluid");
    this->addWidget(this->Layout());

    app->root()->clear();
    app->root()->addWidget(this);

    WTimer *timer = new WTimer(this);
    timer->setInterval(60000);       // every one minute
    timer->timeout().connect(m_pimpl.get(), &Cms::Impl::ValidateSession);
    timer->start();
}
Example #30
0
void AuthService::sendConfirmMail(const std::string& address,
			       const User& user, const std::string& token) const
{
  Mail::Message message;

  WApplication *app = WApplication::instance();
  std::string url
    = app->makeAbsoluteUrl(app->bookmarkUrl(redirectInternalPath_)) + token ;

  message.addRecipient(Mail::To, Mail::Mailbox(address));
  message.setSubject(WString::tr("Wt.Auth.confirmmail.subject"));
  message.setBody(WString::tr("Wt.Auth.confirmmail.body")
		  .arg(user.identity(Identity::LoginName))
		  .arg(token).arg(url));
  message.addHtmlBody(WString::tr("Wt.Auth.confirmmail.htmlbody")
		      .arg(user.identity(Identity::LoginName))
		      .arg(token).arg(url));

  sendMail(message);
}