Ejemplo n.º 1
0
 protected function createComponentLoginForm($name)
 {
     $form = new MyAppForm($this, $name);
     if ($this->useAjax) {
         $form->enableAjax();
     }
     if (!$this->useAutocomplete) {
         $form->getElementPrototype()->autocomplete('off');
     }
     if (isset($this->getPresenter()->translator)) {
         $form->setTranslator($this->getPresenter()->translator);
     }
     if ($this->errorsAsFlashMessages) {
         $form->setErrorsAsFlashMessages();
     }
     $form->addClass('loginFrm');
     $form->addText('username', $this->labels['username'])->addRule(Form::FILLED, 'Enter your username!');
     $form->addPassword('password', $this->labels['password'])->addRule(Form::FILLED, 'Enter your password!');
     if ($this->useRemember) {
         $form->addCheckbox('remember', $this->labels['remember']);
     }
     //	if using labelOver we need to add class to ensure label is visible with javascript disabled
     if ($this->useLabelOver) {
         $form['password']->getLabelPrototype()->class('onlyJS');
         $form['username']->getLabelPrototype()->class('onlyJS');
     }
     $form->addHidden('key');
     $form->addHidden('anchor');
     $form->addSubmit('ok', $this->labels['submit'])->getControlPrototype()->class[] = 'ok-button';
     if ($this->useProtection) {
         $form->addProtection('Form validity time expired. Please send the form again.');
     }
     $form->onSubmit[] = callback($this, 'loginFormSubmitted');
     return $form;
 }
Ejemplo n.º 2
0
 protected function createComponentItemForm()
 {
     $form = new MyAppForm();
     $form->enableAjax();
     $form->enableAjaxFileUpload();
     if (!is_null($this->getTranslator())) {
         $form->setTranslator($this->getTranslator());
     }
     $form->getRenderer()->wrappers['label']['requiredsuffix'] = " *";
     $form->addGroup();
     $form->addText('username', 'User Name')->addRule($form::FILLED)->addRule($form::MIN_LENGTH, NULL, 3)->addRule($form::MAX_LENGTH, NULL, 30)->getControlPrototype()->data('nette-check-url', $this->link('checkAvailability!', array('__NAME__', 'user')))->class[] = 'checkAvailability';
     $form->addText('firstname', 'First Name')->addRule($form::FILLED)->addRule($form::MIN_LENGTH, NULL, 2)->addRule($form::MAX_LENGTH, NULL, 70);
     $form->addText('lastname', 'Last Name')->addRule($form::FILLED)->addRule($form::MIN_LENGTH, NULL, 2)->addRule($form::MAX_LENGTH, NULL, 70);
     if ($this->getAction() === 'add') {
         $form->addPassword('password', 'Password')->addRule($form::FILLED)->addRule($form::MIN_LENGTH, NULL, 6);
         $form->addPassword('password2', 'Confirm Password')->addRule($form::FILLED, 'Confirm user password!')->addRule($form::EQUAL, 'No match for passwords!', $form['password']);
     } elseif ($this->getAction() === 'edit') {
         $form->addPassword('password', 'Password')->setOption('description', 'Fill in only if you want to change current password')->addCondition($form::FILLED)->addRule($form::MIN_LENGTH, NULL, 6);
         $form['password']->getControlPrototype()->autocomplete('off');
         $form->addPassword('password2', 'Confirm Password')->setOption('description', 'Fill in only if you want to change current password')->addConditionOn($form['password'], $form::FILLED)->addRule($form::FILLED, 'Confirm your password!')->addRule($form::EQUAL, 'No match for passwords!', $form['password']);
     }
     $form->addText('email', 'E-Mail')->setEmptyValue('@')->addRule($form::FILLED)->addRule($form::EMAIL)->addRule($form::MAX_LENGTH, NULL, 60);
     if ($this->isClientMode) {
         //		    $form->addSelect('roles', 'Role', $this->prepareRoles())
         $form->addSelect('roles', 'Role', BaseModel::prepareSelect($this->prepareRoles()))->skipFirst()->addRule($form::FILLED);
     } else {
         $form->addMultiSelect('roles', 'Role', $this->prepareRoles(), 7)->addRule($form::FILLED)->addCondition(Form::EQUAL, UsersModel::$clientRolesId)->toggle('supervisorBox')->addCondition(Form::EQUAL, UsersModel::UL_CLIENT_ID)->toggle('clientLogoBox');
         // client as supervisor group
         $form->addGroup()->setOption('container', Html::el('div')->id('supervisorBox'));
         $form->addSelect('supervisor_id', 'Client', $this->prepareClients())->skipFirst()->addConditionOn($form['roles'], Form::EQUAL, UsersModel::$clientRolesId)->addRule(Form::FILLED);
         // client logo group
         $form->addGroup()->setOption('container', Html::el('div')->id('clientLogoBox'));
         // when editing logo is optional
         if ($this->getParam('action') == 'edit') {
             $form->addFile('client_logo', "Client's logo")->setOption('description', 'Choose photo only if you want to change current one')->addCondition(Form::FILLED)->addRule(MyAppForm::SUFFIX, 'Logo must be image (jpg, gif, png)', 'jpg, gif, png')->addRule(Form::MAX_FILE_SIZE, 'File attachment exceeds maximum file size ' . Environment::getConfig("upload")->max_file_size . 'B', Environment::getConfig("upload")->max_file_size);
         } else {
             $form->addFile('client_logo', "Client's logo")->addConditionOn($form['roles'], Form::EQUAL, UsersModel::UL_CLIENT_ID)->addRule(Form::FILLED)->addRule(MyAppForm::SUFFIX, 'Logo must be image (jpg, gif, png)', 'jpg, gif, png')->addRule(Form::MAX_FILE_SIZE, 'File attachment exceeds maximum file size ' . Environment::getConfig("upload")->max_file_size . 'B', Environment::getConfig("upload")->max_file_size);
         }
     }
     $form->addGroup();
     $form->addCheckbox('send_email', 'Send notification email');
     $form->addSubmit('save', 'Add User')->getControlPrototype()->class[] = 'ok-button';
     $_this = $this;
     $form->addSubmit('cancel', 'Cancel')->setValidationScope(NULL)->getControlPrototype()->class[] = 'cancel-button';
     $form['cancel']->onClick[] = function () use($_this) {
         $_this->refresh(null, 'add', array(), true);
     };
     $form->onSubmit[] = callback($this, 'itemFormSubmitted');
     //		$form['save']->onClick[] = callback($this, 'itemFormSubmitted');
     return $form;
 }
 protected function createComponentTempLoginForm()
 {
     $form = new MyAppForm();
     if (isset($this->getPresenter()->translator)) {
         $form->setTranslator($this->getPresenter()->translator);
     }
     $form->addText('email', 'E-mail')->setEmptyValue('@')->addRule(Form::FILLED)->addRule(Form::EMAIL);
     $form->addSubmit('send', 'Log me in!')->getControlPrototype()->class[] = 'ok-button';
     $form->addProtection('Form validity time expired. Please send the form again.');
     $form->onSubmit[] = array($this, 'tempLoginFormSubmitted');
     return $form;
 }
Ejemplo n.º 4
0
 /**
  * factory for form for setting complete user info
  *
  * @return MyAppForm
  */
 protected function createComponentUserInfoForm()
 {
     $form = new MyAppForm();
     $form->getElementPrototype()->class('ajax');
     if (!is_null($this->getTranslator())) {
         $form->setTranslator($this->getTranslator());
     }
     $form->getRenderer()->wrappers['label']['requiredsuffix'] = " *";
     $form->addText('firstname', 'First Name')->addRule(Form::FILLED)->addRule(Form::MIN_LENGTH, NULL, 2)->addRule(Form::MAX_LENGTH, NULL, 70);
     $form->addText('lastname', 'Last Name')->addRule(Form::FILLED)->addRule(Form::MIN_LENGTH, NULL, 2)->addRule(Form::MAX_LENGTH, NULL, 70);
     $form->addText('username', 'User Name')->addRule(Form::FILLED)->addRule(Form::MIN_LENGTH, NULL, 3)->addRule(Form::MAX_LENGTH, NULL, 30);
     $form->addText('email', 'E-Mail')->setEmptyValue('@')->addRule(Form::FILLED)->addRule(Form::EMAIL)->addRule(Form::MAX_LENGTH, NULL, 60);
     $form->addPassword('password', 'Password')->setOption('description', 'Fill in only if you want to change current password')->addCondition(Form::FILLED)->addRule(Form::MIN_LENGTH, NULL, 6);
     $form['password']->getControlPrototype()->autocomplete('off');
     $form->addPassword('password2', 'Confirm Password')->setOption('description', 'Fill in only if you want to change current password')->addConditionOn($form['password'], Form::FILLED)->addRule(Form::FILLED, 'Confirm your password!')->addRule(Form::EQUAL, 'No match for passwords!', $form['password']);
     $form->addPassword("currentPassword", "Current Password", 60)->setOption('description', 'Fill in only if you want to change current password')->addConditionOn($form['password'], Form::FILLED)->addRule(Form::FILLED);
     $form->addSubmit('save', 'Save')->getControlPrototype()->class[] = 'ok-button';
     $form->onSubmit[] = callback($this, 'save');
     return $form;
 }