示例#1
0
/* ****************************************************************************
 * Edit Users
 */
EditUsers::EditUsers(Wt::Dbo::Session& aSession, const std::string& basePath) : session_(aSession), basePath_(basePath)
{
    setStyleClass("user-editor");
    setTemplateText(tr("edit-users-list"));
    limitEdit_  = new Wt::WLineEdit;
    Wt::WPushButton* goLimit = new Wt::WPushButton(tr("go-limit"));
    goLimit->clicked().connect(SLOT(this, EditUsers::LimitList));
    bindWidget("limit-edit",limitEdit_);
    bindWidget("limit-button",goLimit);
    LimitList();
} // end EditUsers::EditUsers
示例#2
0
文件: AuthWidget.C 项目: 913862627/wt
void AuthWidget::updatePasswordLoginView()
{
  if (model_->passwordAuth()) {
    setCondition("if:passwords", true);

    updateView(model_);

    WInteractWidget *login = resolve<WInteractWidget *>("login");

    if (!login) {
      login = new WPushButton(tr("Wt.Auth.login"));
      login->clicked().connect(this, &AuthWidget::attemptPasswordLogin);
      bindWidget("login", login);

      model_->configureThrottling(login);

      if (model_->baseAuth()->emailVerificationEnabled()) {
	WText *text = new WText(tr("Wt.Auth.lost-password"));
	text->clicked().connect(this, &AuthWidget::handleLostPassword);
	bindWidget("lost-password", text);
      } else
	bindEmpty("lost-password");

      if (registrationEnabled_) {
	WInteractWidget *w;
	if (!basePath_.empty()) {
	  w = new WAnchor
	    (WLink(WLink::InternalPath, basePath_ + "register"),
	     tr("Wt.Auth.register"));
	} else {
	  w = new WText(tr("Wt.Auth.register"));
	  w->clicked().connect(this, &AuthWidget::registerNewUser);
	}

	bindWidget("register", w);
      } else
	bindEmpty("register");

      if (model_->baseAuth()->emailVerificationEnabled()
	  && registrationEnabled_)
	bindString("sep", " | ");
      else
	bindEmpty("sep");
    }

    model_->updateThrottling(login);
  } else {
    bindEmpty("lost-password");
    bindEmpty("sep");
    bindEmpty("register");
    bindEmpty("login");
  }
}
示例#3
0
void WTemplateFormView::setFormWidget(WFormModel::Field field,
				      Wt::WWidget *formWidget)
{
  fields_[field] = FieldData();
  fields_[field].formWidget = formWidget;
  bindWidget(field, formWidget);
}
示例#4
0
文件: AuthWidget.C 项目: 913862627/wt
void AuthWidget::createOAuthLoginView()
{
  if (!model_->oAuth().empty()) {
    setCondition("if:oauth", true);

    WContainerWidget *icons = new WContainerWidget();
    icons->setInline(isInline());

    for (unsigned i = 0; i < model_->oAuth().size(); ++i) {
      const OAuthService *auth = model_->oAuth()[i];

      WImage *w = new WImage("css/oauth-" + auth->name() + ".png", icons);
      w->setToolTip(auth->description());
      w->setStyleClass("Wt-auth-icon");
      w->setVerticalAlignment(AlignMiddle);

      OAuthProcess *const process 
	= auth->createProcess(auth->authenticationScope());
#ifndef WT_TARGET_JAVA
      w->clicked().connect(process, &OAuthProcess::startAuthenticate);
#else
      process->connectStartAuthenticate(w->clicked());
#endif

      process->authenticated().connect
	(boost::bind(&AuthWidget::oAuthDone, this, process, _1));

      WObject::addChild(process);
    }

    bindWidget("icons", icons);
  }
}
示例#5
0
void CommentsWidget::show_form_() {
    if (fApp->is_banned()) {
        bindString("add", tr("facts.common.BannedIp"));
    } else {
        bindWidget("add", new CommentAddForm(this));
    }
}
示例#6
0
void WTemplateFormView::updateViewField(WFormModel *model,
					WFormModel::Field field)
{
  const std::string var = field;

  if (model->isVisible(field)) {
    setCondition("if:" + var, true);
    WWidget *edit = resolveWidget(var);
    if (!edit) {
      edit = createFormWidget(field);
      if (!edit) {
	LOG_ERROR("updateViewField: createFormWidget('"
		  << field << "') returned 0");
	return;
      }
      bindWidget(var, edit);
    }

    WFormWidget *fedit = dynamic_cast<WFormWidget *>(edit);
    if (fedit) {
      if (fedit->validator() != model->validator(field) &&
	  model->validator(field))
	fedit->setValidator(model->validator(field));
      updateViewValue(model, field, fedit);
    } else
      updateViewValue(model, field, edit);

    WText *info = resolve<WText *>(var + "-info");
    if (!info) {
      info = new WText();
      bindWidget(var + "-info", info);
    }

    bindString(var + "-label", model->label(field));

    const WValidator::Result& v = model->validation(field);
    info->setText(v.message());
    indicateValidation(field, model->isValidated(field),
		       info, edit, v);
    edit->setDisabled(model->isReadOnly(field));
  } else {
    setCondition("if:" + var, false);
    bindEmpty(var);
    bindEmpty(var + "-info");    
  }
}
示例#7
0
void WTemplateFormView
::setFormWidget(WFormModel::Field field, WWidget *formWidget,
		FieldView *fieldView)
{
  fields_[field] = FieldData();
  fields_[field].formWidget = formWidget;
  fields_[field].updateFunctions = fieldView;

  bindWidget(field, formWidget); 
}
示例#8
0
SpinBoxField::SpinBoxField() : AbstractField(),
		_fieldLabel(new Wt::WText("Campo")),
		_fieldInvalidMessage(new Wt::WText("Dados incorretos")),
		_fieldInput(new Wt::WSpinBox()){

	setEmptyValidator();
	_fieldInput->setMinimum(0);
	_fieldInput->setWidth(100);

	setInvalidMessage("Selecione/Digite um numero valido");

	_setTemplate();
	_fieldInput->setStyleClass("form-control");
	_fieldInvalidMessage->hide();

	bindWidget("label", _fieldLabel);
	bindWidget("info", _fieldInvalidMessage);
	bindWidget("field", _fieldInput);

}
示例#9
0
文件: AuthWidget.C 项目: 913862627/wt
void AuthWidget::createLoggedInView()
{
  setTemplateText(tr("Wt.Auth.template.logged-in"));

  bindString("user-name", login_.user().identity(Identity::LoginName));  

  WPushButton *logout = new WPushButton(tr("Wt.Auth.logout"));
  logout->clicked().connect(this, &AuthWidget::logout);

  bindWidget("logout", logout);
}
示例#10
0
void WTemplateFormView
::setFormWidget(WFormModel::Field field, WWidget *formWidget,
		const boost::function<void()>& updateViewValue,
		const boost::function<void()>& updateModelValue)
{
  fields_[field].formWidget = formWidget;
  fields_[field].updateView = updateViewValue;
  fields_[field].updateModel = updateModelValue;

  bindWidget(field, formWidget); 
}
示例#11
0
CommentsWidget::CommentsWidget(const FactPtr& fact, Wt::WContainerWidget* p):
    Wt::WTemplate(tr("facts.comment.comments_template"), p),
    fact_(fact) {
    dbo::Transaction t(fApp->session());
    Q query = fact->comments().find();
    query.orderBy("comment_index desc");
    CommentsModel* model = new CommentsModel(query, this);
    view_ = new CommentsView(model);
    show_button_();
    bindWidget("comments", view_);
    if (fApp->admin() && !fApp->environment().ajax()) {
        bindWidget("save", new Wt::WPushButton(tr("facts.admin.Save")));
    } else {
        bindString("save", "");
    }
    int index = fApp->comment_index(fact);
    if (index != -1) {
        view_->goto_index(index);
    }
    t.commit();
}
示例#12
0
void WNavigationBar::setTitle(const WString& title, const WLink& link)
{
  WAnchor *titleLink = resolve<WAnchor *>("title-link");

  if (!titleLink) {
    bindWidget("title-link", titleLink = new WAnchor());
    wApp->theme()->apply(this, titleLink, NavBrandRole);
  }
  
  titleLink->setText(title);
  titleLink->setLink(link);
}
示例#13
0
文件: WNavigationBar.C 项目: DTidd/wt
void WNavigationBar::setResponsive(bool responsive)
{
  NavContainer *contents = resolve<NavContainer *>("contents");

  if (responsive) {
    WInteractWidget *collapseButton
      = resolve<WInteractWidget *>("collapse-button");
    WInteractWidget *expandButton
      = resolve<WInteractWidget *>("expand-button");

    if (!collapseButton) {
      bindWidget("collapse-button", collapseButton = createCollapseButton());
      collapseButton->clicked().connect(this,
					&WNavigationBar::collapseContents);

      collapseButton->hide();

      bindWidget("expand-button", expandButton = createExpandButton());
      expandButton->clicked().connect(this,
				      &WNavigationBar::expandContents);
    }

    wApp->theme()->apply(this, contents, NavCollapseRole);

    contents->hide();

    if (contents->isBootstrap2Responsive()) {
      /* Comply with bootstrap responsive CSS assumptions */
      contents->setJavaScriptMember
	("wtAnimatedHidden",
	 "function(hidden) {"
	 """if (hidden) "
	 ""  "this.style.height=''; this.style.display='';"
	 "}");
    }
  } else {
    bindEmpty("collapse-button");
  }
}
示例#14
0
WNavigationBar::WNavigationBar(WContainerWidget *parent)
  : WTemplate(tr("Wt.WNavigationBar.template"), parent)
{
  bindEmpty("collapse-button");
  bindEmpty("expand-button");
  bindEmpty("title-link");
  bindWidget("contents", new NavContainer());

  implementStateless(&WNavigationBar::collapseContents,
		     &WNavigationBar::undoExpandContents);

  implementStateless(&WNavigationBar::expandContents,
		     &WNavigationBar::undoExpandContents);
}
示例#15
0
 CommentAddForm(CommentsWidget* comments):
     Wt::WTemplate(tr("facts.comment.add_template")),
     comments_(comments) {
     username_ = new Wt::WLineEdit();
     username_->setEmptyText(tr("facts.comment.Username"));
     username_->setTextSize(INPUT_SIZE);
     username_->setValidator(new Wt::WLengthValidator(MIN_INPUT_SIZE, INPUT_SIZE));
     username_->validator()->setMandatory(true);
     email_ = new Wt::WLineEdit();
     email_->setEmptyText(tr("facts.comment.Email"));
     email_->setTextSize(INPUT_SIZE);
     email_->setValidator(new Wt::WRegExpValidator(EMAIL_PATTERN));
     text_ = new Wt::WTextEdit();
     text_->setColumns(TEXT_COLUMNS);
     Wt::WPushButton* add_button = new Wt::WPushButton(tr("facts.comment.Add"));
     add_button->clicked().connect(this, &CommentAddForm::add_handler_);
     error_ = new Wt::WText();
     bindWidget("username", username_);
     bindWidget("email", email_);
     bindWidget("text", text_);
     bindWidget("button", add_button);
     bindWidget("error", error_);
 }
示例#16
0
LoginWindow::LoginWindow(WContainerWidget* parent) : MoreAwesomeTemplate(parent) {
    setTemplateText(tr("login-template"));
    addStyleClass("yui-gd dialog form"); // 1/3 + 2/3 style
    bindAndCreateField(_usernameLabel, _usernameEdit, "username");

    // Password
    bindAndCreateField(_passwordLabel, _passwordEdit, "password");
    _passwordEdit->setEchoMode(WLineEdit::Password);

    // Buttons
    bindWidget("btn-bar", _btnBar = new ButtonBar(tr("Login"), tr("Cancel")));
    _btnBar->btn1()->clicked().connect(this, &LoginWindow::handleOKHit);
    _btnBar->btn2()->clicked().connect(this, &LoginWindow::handleCancelHit);

    // Hook up accept and reject signals
    // All these do an accept
    _passwordEdit->enterPressed().connect(this, &LoginWindow::handleOKHit);    

    // These do reject
    _usernameEdit->escapePressed().connect(this, &LoginWindow::handleCancelHit);
    _passwordEdit->escapePressed().connect(this, &LoginWindow::handleCancelHit);
}
示例#17
0
/* ****************************************************************************
 * Limit List
 */
void EditUsers::LimitList()
{
    Wt::WContainerWidget* list = new Wt::WContainerWidget;
    bindWidget("user-list",list);

    typedef Wt::Dbo::collection<Wt::Dbo::ptr<User> > UserList;
    Wt::Dbo::Transaction t(session_);
    UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name");

    Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >* userLinkMap = new Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >(this);
    userLinkMap->mapped().connect(this,&EditUsers::OnUserClicked);
    for (UserList::const_iterator i = users.begin(); i != users.end(); ++i)
    {
        Wt::WText* t = new Wt::WText((*i)->name, list);
        t->setStyleClass("link");
        new Wt::WBreak(list);
        userLinkMap->mapConnect(t->clicked(), (*i).id());
    }
    if (!users.size())
    {
        new Wt::WText(tr("no-users-found"),list);
    }
} // end void EditUsers::LimitList
示例#18
0
void WTemplate::bindString(const std::string& varName, const WString& value,
			   TextFormat textFormat)
{
  WWidget *w = resolveWidget(varName);
  if (w)
    bindWidget(varName, 0);

  WString v = value;

  if (textFormat == XHTMLText && v.literal()) {
    if (!removeScript(v))
      v = escapeText(v, true);
  } else if (textFormat == PlainText)
    v = escapeText(v, true);

  StringMap::const_iterator i = strings_.find(varName);

  if (i == strings_.end() || i->second != v.toUTF8()) {
    strings_[varName] = v.toUTF8();

    changed_ = true;
    repaint(RepaintInnerHtml);  
  }
}
示例#19
0
UpdatePasswordWidget::UpdatePasswordWidget(const User& user,
					   RegistrationModel *registrationModel,
					   AuthModel *authModel,
					   WContainerWidget *parent)
  : WTemplateFormView(tr("Wt.Auth.template.update-password"), parent),
    user_(user),
    registrationModel_(registrationModel),
    authModel_(authModel)
{
  registrationModel_->setValue(RegistrationModel::LoginNameField,
			       user.identity(Identity::LoginName));
  registrationModel_->setReadOnly(RegistrationModel::LoginNameField, true);

  if (authModel_->baseAuth()->emailVerificationEnabled()) {
    /*
     * This is set in the model so that the password checker can take
     * into account whether the password is derived from the email
     * address.
     */
    registrationModel_->setValue(RegistrationModel::EmailField,
			 WT_USTRING::fromUTF8(user.email() + " "
					      + user.unverifiedEmail()));
    registrationModel_->setVisible(RegistrationModel::EmailField, false);
  }

  WPushButton *okButton = new WPushButton(tr("Wt.WMessageBox.Ok"));
  WPushButton *cancelButton = new WPushButton(tr("Wt.WMessageBox.Cancel"));

  if (authModel_) {
    authModel_->setValue(AuthModel::LoginNameField,
			 user.identity(Identity::LoginName));

    updateViewField(authModel_, AuthModel::PasswordField);

    authModel_->configureThrottling(okButton);

    WLineEdit *password = resolve<WLineEdit *>(AuthModel::PasswordField);
    password->setFocus();
  }

  updateView(registrationModel_);

  WLineEdit *password = resolve<WLineEdit *>
    (RegistrationModel::ChoosePasswordField);
  WLineEdit *password2 = resolve<WLineEdit *>
    (RegistrationModel::RepeatPasswordField);
  WText *password2Info = resolve<WText *>
    (RegistrationModel::RepeatPasswordField + std::string("-info"));

  registrationModel_->validatePasswordsMatchJS(password,
					       password2, password2Info);

  if (!authModel_)
    password->setFocus();

  okButton->clicked().connect(this, &UpdatePasswordWidget::doUpdate);
  cancelButton->clicked().connect(this, &UpdatePasswordWidget::close);

  bindWidget("ok-button", okButton);
  bindWidget("cancel-button", cancelButton);

}
示例#20
0
void RegistrationWidget::update()
{
  if (model_->passwordAuth())
    bindString("password-description",
	       tr("Wt.Auth.password-registration"));
  else
    bindEmpty("password-description");

  updateView(model_);

  if (!created_) {
    WLineEdit *password = resolve<WLineEdit *>
      (RegistrationModel::ChoosePasswordField);
    WLineEdit *password2 = resolve<WLineEdit *>
      (RegistrationModel::RepeatPasswordField);
    WText *password2Info = resolve<WText *>
      (RegistrationModel::RepeatPasswordField + std::string("-info"));

    if (password && password2 && password2Info)
      model_->validatePasswordsMatchJS(password, password2, password2Info);
  }

  WAnchor *isYou = resolve<WAnchor *>("confirm-is-you");
  if (!isYou) {
    isYou = new WAnchor(std::string("#"), tr("Wt.Auth.confirm-is-you"));
    isYou->hide();
    bindWidget("confirm-is-you", isYou);
  }

  if (model_->isConfirmUserButtonVisible()) {
    if (!isYou->clicked().isConnected())
      isYou->clicked().connect(this, &RegistrationWidget::confirmIsYou);
    isYou->show();
  } else
    isYou->hide();

  if (model_->isFederatedLoginVisible()) {
    if (!conditionValue("if:oauth")) {
      setCondition("if:oauth", true);
      if (model_->passwordAuth())
	bindString("oauth-description", tr("Wt.Auth.or-oauth-registration"));
      else
	bindString("oauth-description", tr("Wt.Auth.oauth-registration"));

      WContainerWidget *icons = new WContainerWidget();
      icons->addStyleClass("Wt-field");

      for (unsigned i = 0; i < model_->oAuth().size(); ++i) {
	const OAuthService *service = model_->oAuth()[i];

	WImage *w = new WImage("css/oauth-" + service->name() + ".png", icons);
	w->setToolTip(service->description());
	w->setStyleClass("Wt-auth-icon");
	w->setVerticalAlignment(AlignMiddle);
	OAuthProcess *const process
	  = service->createProcess(service->authenticationScope());
	w->clicked().connect(process, &OAuthProcess::startAuthenticate);

	process->authenticated().connect
	  (boost::bind(&RegistrationWidget::oAuthDone, this, process, _1));

	WObject::addChild(process);
      }

      bindWidget("icons", icons);
    }
  } else {
    setCondition("if:oauth", false);
    bindEmpty("icons");
  }

  if (!created_) {
    WPushButton *okButton = new WPushButton(tr("Wt.Auth.register"));
    WPushButton *cancelButton = new WPushButton(tr("Wt.WMessageBox.Cancel"));

    bindWidget("ok-button", okButton);
    bindWidget("cancel-button", cancelButton);

    okButton->clicked().connect(this, &RegistrationWidget::doRegister);
    cancelButton->clicked().connect(this, &RegistrationWidget::close);

    created_ = true;
  }
}
示例#21
0
void WTemplate::bindEmpty(const std::string& varName)
{
  bindWidget(varName, 0);
}
示例#22
0
    // inline constructor
    UserFormView() {
        model_ = new UserFormModel(this);

        setTemplateText(tr("userForm-template"));
        addFunction("id", &WTemplate::Functions::id);

        /*
	 * First Name
	 */
	setFormWidget(UserFormModel::FirstNameField, new Wt::WLineEdit());

	/*
	 * Last Name
	 */
	setFormWidget(UserFormModel::LastNameField, new Wt::WLineEdit());

	/*
	 * Country
	 */
	Wt::WComboBox *countryCB = new Wt::WComboBox();
	countryCB->setModel(model_->countryModel());

	countryCB->activated().connect(std::bind([=] () {
	    std::string code = model_->countryCode(countryCB->currentIndex());
	    model_->updateCityModel(code);
	}));

	setFormWidget(UserFormModel::CountryField, countryCB,
            [=] () { // updateViewValue()
	        std::string code = boost::any_cast<std::string>
		    (model_->value(UserFormModel::CountryField));
		int row = model_->countryModelRow(code);
		countryCB->setCurrentIndex(row);
	    },

            [=] () { // updateModelValue()
	        std::string code = model_->countryCode(countryCB->currentIndex());
		model_->setValue(UserFormModel::CountryField, code);
            });

	/*
	 * City
	 */
	Wt::WComboBox *cityCB = new Wt::WComboBox();
	cityCB->setModel(model_->cityModel());
	setFormWidget(UserFormModel::CityField, cityCB);

	/*
	 * Birth Date
	 */
	Wt::WLineEdit *dateEdit = new Wt::WLineEdit();
	Wt::WDatePicker *birthDP = new Wt::WDatePicker(dateEdit);
	bindWidget("birth-dp", birthDP);

	setFormWidget(UserFormModel::BirthField, dateEdit,
	    [=] () { // updateViewValue()
	        Wt::WDate date = boost::any_cast<Wt::WDate>
		    (model_->value(UserFormModel::BirthField));
                birthDP->setDate(date);
	    }, 

            [=] () { // updateModelValue()
	        Wt::WDate date = birthDP->date();
                model_->setValue(UserFormModel::BirthField, date);
	    });

        /*
	 * Children
	 */ 
	setFormWidget(UserFormModel::ChildrenField, new Wt::WSpinBox());

	/*
	 * Remarks
	 */
	Wt::WTextArea *remarksTA = new Wt::WTextArea();
	remarksTA->setColumns(40);
	remarksTA->setRows(5);
	setFormWidget(UserFormModel::RemarksField, remarksTA);

	/*
	 * Title & Buttons
	 */
        Wt::WString title = Wt::WString("Create new user");
        bindString("title", title);

        Wt::WPushButton *button = new Wt::WPushButton("Save");
        bindWidget("submit-button", button);

        bindString("submit-info", Wt::WString());

        button->clicked().connect(this, &UserFormView::process);

        updateView(model_);
    }
示例#23
0
UpdatePasswordWidget::UpdatePasswordWidget(const User& user,
					   const AbstractPasswordService& auth,
					   Login& login,
					   bool promptPassword,
					   WContainerWidget *parent)
  : WTemplate(tr("Wt.Auth.template.update-password"), parent),
    user_(user),
    promptPassword_(promptPassword),
    validated_(false),
    enterPasswordFields_(0)
{
  addFunction("id", &WTemplate::Functions::id);
  addFunction("tr", &WTemplate::Functions::tr);

  WLineEdit *nameEdit = new WLineEdit(user.identity(Identity::LoginName));
  nameEdit->disable();
  nameEdit->addStyleClass("Wt-disabled");
  bindWidget("user-name", nameEdit);

  WPushButton *okButton = new WPushButton(tr("Wt.WMessageBox.Ok"));
  WPushButton *cancelButton = new WPushButton(tr("Wt.WMessageBox.Cancel"));

  if (promptPassword_) {
    setCondition("if:old-password", true);
    WLineEdit *oldPasswd = new WLineEdit();
    WText *oldPasswdInfo = new WText();

    enterPasswordFields_ = new EnterPasswordFields(auth,
						   oldPasswd, oldPasswdInfo,
						   okButton, this);

    oldPasswd->setFocus();

    bindWidget("old-password", oldPasswd);
    bindWidget("old-password-info", oldPasswdInfo);
  }

  WLineEdit *password = new WLineEdit();
  password->setEchoMode(WLineEdit::Password);
  password->keyWentUp().connect
    (boost::bind(&UpdatePasswordWidget::checkPassword, this));
  password->changed().connect
    (boost::bind(&UpdatePasswordWidget::checkPassword, this));

  WText *passwordInfo = new WText();

  WLineEdit *password2 = new WLineEdit();
  password2->setEchoMode(WLineEdit::Password);
  password2->changed().connect
    (boost::bind(&UpdatePasswordWidget::checkPassword2, this));

  WText *password2Info = new WText();

  bindWidget("choose-password", password);
  bindWidget("choose-password-info", passwordInfo);

  bindWidget("repeat-password", password2);
  bindWidget("repeat-password-info", password2Info);

  model_ = new RegistrationModel(auth.baseAuth(), *user.database(),
				 login, this);

  model_->addPasswordAuth(&auth);

  model_->setValue(RegistrationModel::LoginName,
		   user.identity(Identity::LoginName));
  model_->setValue(RegistrationModel::Email,
		   WT_USTRING::fromUTF8(user.email() + " "
					+ user.unverifiedEmail()));

  model_->validatePasswordsMatchJS(password, password2, password2Info);

  passwordInfo->setText(model_->validationResult
			(RegistrationModel::Password).message());
  password2Info->setText(model_->validationResult
			 (RegistrationModel::Password2).message());

  okButton->clicked().connect(this, &UpdatePasswordWidget::doUpdate);
  cancelButton->clicked().connect(this, &UpdatePasswordWidget::close);

  bindWidget("ok-button", okButton);
  bindWidget("cancel-button", cancelButton);

  if (!promptPassword_)
    password->setFocus();
}
示例#24
0
 void setBody(WWidget* newChild) { bindWidget("content", newChild); }
示例#25
0
    // inline constructor
    UserFormView() {
        model = std::make_shared<UserFormModel>();

        setTemplateText(tr("userForm-template"));
        addFunction("id", &WTemplate::Functions::id);
        addFunction("block", &WTemplate::Functions::id);

        /*
	 * First Name
	 */
	setFormWidget(UserFormModel::FirstNameField,
	              Wt::cpp14::make_unique<Wt::WLineEdit>());

	/*
	 * Last Name
	 */
	setFormWidget(UserFormModel::LastNameField,
	              Wt::cpp14::make_unique<Wt::WLineEdit>());

	/*
	 * Country
	 */
	auto countryCB = Wt::cpp14::make_unique<Wt::WComboBox>();
	auto countryCB_ = countryCB.get();
	countryCB->setModel(model->countryModel());

	countryCB_->activated().connect([=] {
	    std::string code = model->countryCode(countryCB_->currentIndex());
	    model->updateCityModel(code);
	});

        setFormWidget(UserFormModel::CountryField, std::move(countryCB),
            [=] { // updateViewValue()
                std::string code =
                    Wt::asString(model->value(UserFormModel::CountryField)).toUTF8();
		int row = model->countryModelRow(code);
		countryCB_->setCurrentIndex(row);
	    },

            [=] { // updateModelValue()
                std::string code = model->countryCode(countryCB_->currentIndex());
		model->setValue(UserFormModel::CountryField, code);
            });

	/*
	 * City
	 */
	auto cityCB = Wt::cpp14::make_unique<Wt::WComboBox>();
	cityCB->setModel(model->cityModel());
	setFormWidget(UserFormModel::CityField, std::move(cityCB));

	/*
	 * Birth Date
	 */
	auto dateEdit = Wt::cpp14::make_unique<Wt::WDateEdit>();
	auto dateEdit_ = dateEdit.get();
	setFormWidget(UserFormModel::BirthField, std::move(dateEdit),
	    [=] { // updateViewValue()
	        Wt::WDate date = Wt::cpp17::any_cast<Wt::WDate>
		    (model->value(UserFormModel::BirthField));
		dateEdit_->setDate(date);
	    }, 

            [=] { // updateModelValue()
                Wt::WDate date = dateEdit_->date();
                model->setValue(UserFormModel::BirthField, date);
	    });

        /*
	 * Children
	 */ 
	setFormWidget(UserFormModel::ChildrenField, Wt::cpp14::make_unique<Wt::WSpinBox>());

	/*
	 * Remarks
	 */
	auto remarksTA = Wt::cpp14::make_unique<Wt::WTextArea>();
	remarksTA->setColumns(40);
	remarksTA->setRows(5);
	setFormWidget(UserFormModel::RemarksField, std::move(remarksTA));

	/*
	 * Title & Buttons
	 */
	Wt::WString title = Wt::WString("Create new user");
        bindString("title", title);

        auto button = Wt::cpp14::make_unique<Wt::WPushButton>("Save");
        auto button_ = bindWidget("submit-button", std::move(button));

        bindString("submit-info", Wt::WString());

        button_->clicked().connect(this, &UserFormView::process);

        updateView(model.get());
    }
示例#26
0
文件: GoogleMap.cpp 项目: AmesianX/wt
    GoogleMapExample()
        : WContainerWidget()
    {
        auto layout = setLayout(cpp14::make_unique<WHBoxLayout>());

	setHeight(400);

	auto map = cpp14::make_unique<WGoogleMap>(GoogleMapsVersion::v3);
	map_ = map.get();
	layout->addWidget(std::move(map), 1);

	map_->setMapTypeControl(MapTypeControl::Default);
	map_->enableScrollWheelZoom();

	auto controls =
	    cpp14::make_unique<WTemplate>(tr("graphics-GoogleMap-controls"));
	auto controls_ = controls.get();
	layout->addWidget(std::move(controls));

	auto zoomIn = cpp14::make_unique<WPushButton>("+");
	auto zoomIn_ = controls_->bindWidget("zoom-in", std::move(zoomIn));
	zoomIn_->addStyleClass("zoom");

	zoomIn_->clicked().connect([=] {
	    map_->zoomIn();
	});

	auto zoomOut = cpp14::make_unique<WPushButton>("-");
	auto zoomOut_ = controls_->bindWidget("zoom-out", std::move(zoomOut));
	zoomOut_->addStyleClass("zoom");

        zoomOut_->clicked().connect([=] {
            map_->zoomOut();
	});

	std::string cityNames[] = { "Brussels", "Lisbon", "Paris" };
	WGoogleMap::Coordinate cityCoords[] = {
	    WGoogleMap::Coordinate(50.85034,4.35171),
	    WGoogleMap::Coordinate(38.703731,-9.135475),
	    WGoogleMap::Coordinate(48.877474, 2.312579)
	};
	    
	for (unsigned i = 0; i < 3; ++i) {
	    auto city = cpp14::make_unique<WPushButton>(cityNames[i]);
	    auto city_ = controls_->bindWidget(cityNames[i], std::move(city));

	    WGoogleMap::Coordinate coord = cityCoords[i];
	    city_->clicked().connect([=] {
		map_->panTo(coord);
	    });
	}

	auto reset = cpp14::make_unique<WPushButton>("Reset");
	auto reset_ = controls_->bindWidget("emweb", std::move(reset));

        reset_->clicked().connect([=] {
            this->panToEmWeb();
        });

	auto savePosition =
	    cpp14::make_unique<WPushButton>("Save current position");
	auto savePosition_ = controls_->bindWidget("save-position", std::move(savePosition));

        savePosition_->clicked().connect([=] {
            this->savePosition();
        });

	auto returnToPosition = cpp14::make_unique<WPushButton>("Return to saved position");
	returnToPosition_ = controls_->bindWidget("return-to-saved-position", std::move(returnToPosition));
	returnToPosition_->setEnabled(false);

	returnToPosition_->clicked().connect([=] {
            map_->returnToSavedPosition();
        });

	mapTypeModel_ = std::make_shared<WStringListModel>();
	addMapTypeControl("No control", MapTypeControl::None);
	addMapTypeControl("Default", MapTypeControl::Default);
	addMapTypeControl("Menu", MapTypeControl::Menu);
	if (map_->apiVersion() == GoogleMapsVersion::v2)
	    addMapTypeControl("Hierarchical",
			      MapTypeControl::Hierarchical);
	if (map_->apiVersion() == GoogleMapsVersion::v3)
	    addMapTypeControl("Horizontal bar",
			      MapTypeControl::HorizontalBar);

	auto menuControls = cpp14::make_unique<WComboBox>();
	auto menuControls_ = controls_->bindWidget("control-menu-combo", std::move(menuControls));
	menuControls_->setModel(mapTypeModel_);
	menuControls_->setCurrentIndex(1);

        menuControls_->activated().connect([=] (int mapType) {
            this->setMapTypeControl(mapType);
        });

	auto draggingCB = cpp14::make_unique<WCheckBox>("Enable dragging");
	auto draggingCB_ = controls_->bindWidget("dragging-cb", std::move(draggingCB));
	draggingCB_->setChecked(true);
	map_->enableDragging();

        draggingCB_->checked().connect([=] {
            map_->enableDragging();
        });

        draggingCB_->unChecked().connect([=] {
            map_->disableDragging();
        });

        auto enableDoubleClickZoomCB =
            cpp14::make_unique<WCheckBox>("Enable double click zoom");
        auto enableDoubleClickZoomCB_ =
            controls_->bindWidget("double-click-zoom-cb", std::move(enableDoubleClickZoomCB));
        enableDoubleClickZoomCB_->setChecked(false);
	map_->disableDoubleClickZoom();

        enableDoubleClickZoomCB_->checked().connect([=] {
            map_->enableDoubleClickZoom();
	});

        enableDoubleClickZoomCB_->unChecked().connect([=] {
            map_->disableDoubleClickZoom();
        });

        auto enableScrollWheelZoomCB =
            cpp14::make_unique<WCheckBox>("Enable scroll wheel zoom");
        auto enableScrollWheelZoomCB_ =
            controls_->bindWidget("scroll-wheel-zoom-cb", std::move(enableScrollWheelZoomCB));
        enableScrollWheelZoomCB_->setChecked(true);
	map_->enableScrollWheelZoom();

        enableScrollWheelZoomCB_->checked().connect([=] {
            map_->enableScrollWheelZoom();
        });

        enableScrollWheelZoomCB_->unChecked().connect([=] {
            map_->disableScrollWheelZoom();
        });

        std::vector<WGoogleMap::Coordinate> road = roadDescription();

        map_->addPolyline(road, WColor(0, 191, 255));

	//Koen's favourite bar!
	map_->addMarker(WGoogleMap::Coordinate(50.885069,4.71958));

	map_->setCenter(road[road.size()-1]);

	map_->openInfoWindow(road[0],
           "<img src=\"http://www.emweb.be/css/emweb_small.jpg\" />"
           "<p><strong>Emweb office</strong></p>");

        map_->clicked().connect([=] (WGoogleMap::Coordinate c) {
            this->googleMapClicked(c);
        });

	map_->doubleClicked().connect([=] (WGoogleMap::Coordinate c) {
            this->googleMapDoubleClicked(c);
        });
    }
示例#27
0
/* ****************************************************************************
 * Edit User
 */
EditUser::EditUser(Wt::Dbo::Session& aSession) : Wt::WTemplate(tr("edit-user")), session_(aSession), roleButton_(new Wt::WPushButton)
{
    bindWidget("role-button",roleButton_);
    roleButton_->clicked().connect(SLOT(this, EditUser::SwitchRole));
} // end EditUser::EditUser
示例#28
0
void CommentsWidget::show_button_() {
    Wt::WPushButton* add = new Wt::WPushButton(tr("facts.comment.Add"));
    add->clicked().connect(this, &CommentsWidget::show_form_);
    bindWidget("add", add);
}