Example #1
0
 public function createComponentForm()
 {
     $form = new \RequestButton\RequestButtonReceiver();
     $form->setTranslator($this->translator);
     $form->addUpload('file', 'File')->addRule(FORM::MAX_FILE_SIZE, 'File is too big! Please, choose smaller one.', 3 * 1024 * 1024);
     $form->addText('name', 'Name')->addRule(Form::FILLED, 'Please, insert name of the file.');
     $form->addTextArea('description', 'Description');
     $form->addTextArea('note', 'Note');
     $form->addSelect('user_id', 'Author', $this->system->getAccountsToSelect())->value = $this->user->isLoggedIn() ? $this->user->getIdentity()->id : NULL;
     $form->addCheckbox('visible', 'visible')->setDefaultValue(1);
     $form->addCheckbox('lock', 'locked');
     $form->addHidden('backlink');
     $form->onSuccess[] = array($this, 'saveItem');
     if (!$this->isRequestButton) {
         if ($this->getView() == 'add') {
             $form->addSubmit('add', 'Save & Add next')->getControlPrototype()->class('primary');
             $form->addSubmit('leave', 'Save & Leave');
         } else {
             $form->addHidden('id');
             $form->addSubmit('leave', 'Save & Leave')->getControlPrototype()->class('primary');
             $form->addSubmit('add', 'Save & Add new');
         }
         $form->addSubmit('save', 'Save');
         $form->addRequestButtonBack('back', 'Cancel & Back')->getControlPrototype();
         $form->addSubmit('cancel', 'Cancel')->setValidationScope(FALSE)->onClick[] = 'CancelClicked';
         $form['cancel']->getControlPrototype()->class('cancel');
     } else {
         $form->addSubmit('save', 'Save')->getControlPrototype()->class('primary');
         $form->addRequestButtonBack('back', 'Cancel')->getControlPrototype()->class('cancel');
     }
     return $form;
 }