public function editInstance() { $clazz = $this->getCurrentClass(); $instance = $this->getCurrentInstance(); $myFormContainer = new \tao_actions_form_Instance($clazz, $instance); $myForm = $myFormContainer->getForm(); $nameElement = $myForm->getElement(\tao_helpers_Uri::encode(WebBrowserService::PROPERTY_NAME)); $versionElement = $myForm->getElement(\tao_helpers_Uri::encode(WebBrowserService::PROPERTY_VERSION)); $nameElement->addClass('select2'); $versionElement->setHelp("<span class=\"icon-help tooltipstered\" data-tooltip=\".web-browser-form .browser-version-tooltip-content\" data-tooltip-theme=\"info\"></span>"); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $values = $myForm->getValues(); // save properties $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($instance); $instance = $binder->bind($values); $message = __('Instance saved'); $this->setData('message', $message); $this->setData('reload', true); } } $this->setData('formTitle', __('Edit Authorized Web Browser')); $this->setData('myForm', $myForm->render()); $this->setView('WebBrowsers/form.tpl'); }
/** * Edit a Test Center instance * @return void */ public function editCenter() { $clazz = $this->getCurrentClass(); $testcenter = $this->getCurrentInstance(); $formContainer = new \tao_actions_form_Instance($clazz, $testcenter); $myForm = $formContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($testcenter); $testcenter = $binder->bind($myForm->getValues()); $this->setData("selectNode", \tao_helpers_Uri::encode($testcenter->getUri())); $this->setData('message', __('Test center saved')); $this->setData('reload', true); } } $memberProperty = new \core_kernel_classes_Property(TestCenterService::PROPERTY_MEMBERS_URI); $memberForm = \tao_helpers_form_GenerisTreeForm::buildReverseTree($testcenter, $memberProperty); $memberForm->setData('title', __('Select test takers for the test center')); $this->setData('memberForm', $memberForm->render()); $groupProperty = new \core_kernel_classes_Property(TestCenterService::PROPERTY_DELIVERY_URI); $groupForm = \tao_helpers_form_GenerisTreeForm::buildTree($testcenter, $groupProperty); $groupForm->setData('title', __('Select deliveries available at the test center')); $this->setData('groupForm', $groupForm->render()); $proctorProperty = new \core_kernel_classes_Property(TestCenterService::PROPERTY_PROCTORS_URI); $proctorForm = \tao_helpers_form_GenerisTreeForm::buildReverseTree($testcenter, $proctorProperty); $proctorForm->setData('title', __('Select proctors for the test center')); $this->setData('proctorForm', $proctorForm->render()); $this->setData('formTitle', __('Edit test center')); $this->setData('myForm', $myForm->render()); $this->setView('form_test_center.tpl'); }
/** * Edit a group instance * @return void */ public function editProcess() { $clazz = $this->getCurrentClass(); $process = $this->getCurrentInstance(); $excludedProperties = array(PROPERTY_PROCESS_VARIABLES, PROPERTY_PROCESS_ACTIVITIES, PROPERTY_PROCESS_ROOT_ACTIVITIES); $formContainer = new tao_actions_form_Instance($clazz, $process, array('excludedProperties' => $excludedProperties)); $myForm = $formContainer->getForm(); //@TODO : put into the process definition service: $aclModes = array(tao_helpers_Uri::encode(INSTANCE_ACL_ROLE) => 'Role', tao_helpers_Uri::encode(INSTANCE_ACL_ROLE_RESTRICTED_USER) => 'User'); $myForm->getElement(tao_helpers_Uri::encode(PROPERTY_PROCESS_INIT_ACL_MODE))->setOptions($aclModes); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($process); $process = $binder->bind($myForm->getValues()); $this->setData("selectNode", tao_helpers_Uri::encode($process->getUri())); $this->setData('message', __('Process saved')); $this->setData('reload', true); } } $this->setData('uri', tao_helpers_Uri::encode($process->getUri())); $this->setData('classUri', tao_helpers_Uri::encode($clazz->getUri())); $this->setData('formTitle', 'Process properties'); $this->setData('myForm', $myForm->render()); $this->setView('form_process.tpl'); }
/** * Edit a Test Center instance * @return void */ public function editCenter() { $clazz = $this->getCurrentClass(); $testCenter = $this->getCurrentInstance(); $formContainer = new \tao_actions_form_Instance($clazz, $testCenter); $myForm = $formContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($testCenter); $testCenter = $binder->bind($myForm->getValues()); $this->setData("selectNode", \tao_helpers_Uri::encode($testCenter->getUri())); $this->setData('message', $this->convert('Test center saved')); $this->setData('reload', true); } } $childrenProperty = new \core_kernel_classes_Property(TestCenterService::PROPERTY_CHILDREN_URI); $childrenForm = \tao_helpers_form_GenerisTreeForm::buildTree($testCenter, $childrenProperty); $childrenForm->setHiddenNodes(array($testCenter->getUri())); $childrenForm->setTitle($this->convert('Define sub-centers')); $this->setData('childrenForm', $childrenForm->render()); $administratorProperty = new \core_kernel_classes_Property(TestCenterService::PROPERTY_ADMINISTRATOR_URI); $administratorForm = \tao_helpers_form_GenerisTreeForm::buildReverseTree($testCenter, $administratorProperty); $administratorForm->setData('title', $this->convert('Assign administrator')); $this->setData('administratorForm', $administratorForm->render()); $proctorProperty = new \core_kernel_classes_Property(ProctorManagementService::PROPERTY_ASSIGNED_PROCTOR_URI); $proctorForm = \tao_helpers_form_GenerisTreeForm::buildReverseTree($testCenter, $proctorProperty); $proctorForm->setData('title', $this->convert('Assign proctors')); $this->setData('proctorForm', $proctorForm->render()); $this->setData('formTitle', $this->convert('Edit test center')); $this->setData('testCenter', $testCenter->getUri()); $this->setData('myForm', $myForm->render()); $this->setView('form_test_center.tpl'); }
protected function initElements() { parent::initElements(); $labelElt = $this->form->getElement(\tao_helpers_Uri::encode(RDFS_LABEL)); if ($labelElt !== null) { $labelElt->addAttribute('noLabel', true); $labelElt->addAttribute('class', 'full-width js-label'); $labelElt->addAttribute('value', '{{label}}'); $labelElt->setName('label'); $labelElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('NotEmpty'))); $this->form->addElement($labelElt); } $maxExecElt = $this->form->getElement(\tao_helpers_Uri::encode(TAO_DELIVERY_MAXEXEC_PROP)); if ($maxExecElt !== null) { $maxExecElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('Integer', array('min' => 1)))); $maxExecElt->addAttribute('value', '{{maxexec}}'); $maxExecElt->addAttribute('noLabel', true); $maxExecElt->setName('maxexec'); $maxExecElt->addAttribute('class', 'full-width js-maxexec'); $this->form->addElement($maxExecElt); } $resultServerElt = $this->form->getElement(\tao_helpers_Uri::encode(TAO_DELIVERY_RESULTSERVER_PROP)); if ($resultServerElt !== null) { $resultServerElt->addAttribute('noLabel', true); $resultServerElt->addAttribute('class', 'full-width'); $resultServerElt->setName('resultserver'); $resultServerElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('NotEmpty'))); $this->form->addElement($resultServerElt); } $recurrenceRuleElt = $this->form->getElement(\tao_helpers_Uri::encode(DeliveryScheduleService::TAO_DELIVERY_RRULE_PROP)); if ($recurrenceRuleElt !== null) { $recurrenceRuleElt->setName('rrule'); $this->form->addElement($recurrenceRuleElt); } }
/** * Short description of method initElements * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function initElements() { parent::initElements(); $codeElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_PROCESSVARIABLES_CODE)); $codeElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $codeElt->addValidator(new wfAuthoring_actions_form_validators_VariableCode(array('uri' => $this->getInstance()->getUri()))); }
/** * edit a test instance * @requiresRight id READ */ public function editTest() { $test = new core_kernel_classes_Resource($this->getRequestParameter('id')); if (!$this->isLocked($test)) { // my lock $lock = LockManager::getImplementation()->getLockData($test); if (!is_null($lock) && $lock->getOwnerId() == common_session_SessionManager::getSession()->getUser()->getIdentifier()) { $this->setData('lockDate', $lock->getCreationTime()); $this->setData('id', $lock->getResource()->getUri()); } $clazz = $this->getCurrentClass(); $formContainer = new tao_actions_form_Instance($clazz, $test); $myForm = $formContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $propertyValues = $myForm->getValues(); // don't hande the testmodel via bindProperties if (array_key_exists(PROPERTY_TEST_TESTMODEL, $propertyValues)) { $modelUri = $propertyValues[PROPERTY_TEST_TESTMODEL]; unset($propertyValues[PROPERTY_TEST_TESTMODEL]); if (!empty($modelUri)) { $testModel = new core_kernel_classes_Resource($modelUri); $this->service->setTestModel($test, $testModel); } } else { common_Logger::w('No testmodel on test form', 'taoTests'); } //then save the property values as usual $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($test); $test = $binder->bind($propertyValues); //edit process label: $this->service->onChangeTestLabel($test); $this->setData("selectNode", tao_helpers_Uri::encode($test->getUri())); $this->setData('message', __('Test saved')); $this->setData('reload', true); } } $myForm->removeElement(tao_helpers_Uri::encode(TEST_TESTCONTENT_PROP)); $this->setData('uri', tao_helpers_Uri::encode($test->getUri())); $this->setData('classUri', tao_helpers_Uri::encode($clazz->getUri())); $this->setData('formTitle', __('Test properties')); $this->setData('myForm', $myForm->render()); $this->setView('Tests/editTest.tpl'); } }
/** * Edit an instances * @return void */ public function sasEditInstance() { $clazz = $this->getCurrentClass(); $instance = $this->getCurrentInstance(); $formContainer = new tao_actions_form_Instance($clazz, $instance); $myForm = $formContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($instance); $instance = $binder->bind($myForm->getValues()); $instance = $this->service->setDefaultItemContent($instance); $this->setData('message', __('Item saved')); } } $this->setData('uri', tao_helpers_Uri::encode($instance->getUri())); $this->setData('classUri', tao_helpers_Uri::encode($clazz->getUri())); $this->setData('formTitle', __('Edit item')); $this->setData('myForm', $myForm->render()); $this->setView('form.tpl', 'tao'); }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { parent::initElements(); $elements = $this->form->getElements(); $this->form->setElements(array()); $currentLangElt = tao_helpers_form_FormFactory::getElement('current_lang', 'Textbox'); $currentLangElt->setDescription(__('Current language')); $currentLangElt->setAttributes(array('readonly' => 'true')); $currentLangElt->setValue(\common_session_SessionManager::getSession()->getDataLanguage()); //API lang /data lang $this->form->addElement($currentLangElt); $dataLangElement = tao_helpers_form_FormFactory::getElement('translate_lang', 'Combobox'); $dataLangElement->setDescription(__('Translate to')); $dataLangElement->setOptions(tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA))); $dataLangElement->setEmptyOption(__('Select a language')); $dataLangElement->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $this->form->addElement($dataLangElement); $this->form->createGroup('translation_info', __('Translation parameters'), array('current_lang', 'translate_lang')); $dataGroup = array(); foreach ($elements as $element) { if ($element instanceof tao_helpers_form_elements_Hidden || $element->getName() == 'uri' || $element->getName() == 'classUri') { $this->form->addElement($element); } else { $propertyUri = tao_helpers_Uri::decode($element->getName()); $property = new core_kernel_classes_Property($propertyUri); //translate only language dependent properties or Labels //supported widget are: Textbox, TextArea, HtmlArea //@todo support other widgets if ($property->isLgDependent() && ($element instanceof tao_helpers_form_elements_Textbox || $element instanceof tao_helpers_form_elements_TextArea || $element instanceof tao_helpers_form_elements_HtmlArea) || $propertyUri == RDFS_LABEL) { $translatedElt = clone $element; $viewElt = tao_helpers_form_FormFactory::getElement('view_' . $element->getName(), 'Label'); $viewElt->setDescription($element->getDescription()); $viewElt->setValue($element->getValue()); $viewElt->setAttribute('no-format', true); if ($element instanceof tao_helpers_form_elements_HtmlArea) { $viewElt->setAttribute('htmlentities', false); } $this->form->addElement($viewElt); $dataGroup[] = $viewElt->getName(); $translatedElt->setDescription(' '); $translatedElt->setValue(''); if ($propertyUri == RDFS_LABEL) { $translatedElt->setForcedValid(); } $this->form->addElement($translatedElt); $dataGroup[] = $translatedElt->getName(); } } } $this->form->createGroup('translation_form', __('Translate'), $dataGroup); }
/** * Edit a delviery instance * @return void */ public function editCampaign() { $clazz = $this->getCurrentClass(); $campaign = $this->getCurrentInstance(); $formContainer = new tao_actions_form_Instance($clazz, $campaign); $myForm = $formContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($campaign); $campaign = $binder->bind($myForm->getValues()); $this->setData("selectNode", tao_helpers_Uri::encode($campaign->getUri())); $this->setData('message', __('Campaign saved')); $this->setData('reload', true); } } //get the deliveries related to this delivery campaign $prop = new core_kernel_classes_Property(TAO_DELIVERY_CAMPAIGN_PROP); $tree = tao_helpers_form_GenerisTreeForm::buildReverseTree($campaign, $prop); $this->setData('deliveryTree', $tree->render()); $this->setData('formTitle', __('Edit Campaign')); $this->setData('myForm', $myForm->render()); $this->setView('form_campaign.tpl'); }
/** * Short description of method initElements * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function initElements() { parent::initElements(); $encodedIncludesRolePropertyUri = tao_helpers_Uri::encode(PROPERTY_ROLE_INCLUDESROLE); $encodedInstanceUri = tao_helpers_Uri::encode($this->getInstance()->getUri()); $rolesElement = $this->form->getElement($encodedIncludesRolePropertyUri); if (!is_null($rolesElement)) { $rolesOptions = $rolesElement->getOptions(); // remove the role itself in the list of includable roles // to avoid cyclic inclusions (even if the system supports it). if (array_key_exists($encodedInstanceUri, $rolesOptions)) { unset($rolesOptions[$encodedInstanceUri]); } $rolesElement->setOptions($rolesOptions); } }
protected function initForm() { parent::initForm(); $bottom = $this->form->getActions('bottom'); $top = $this->form->getActions('top'); $edit = \tao_helpers_form_FormFactory::getElement('edit', 'Free'); $value = ''; if ($edit) { $value .= '<button type="button" id="edit-media" data-classuri="' . $this->getClazz()->getUri() . '" data-uri="' . $this->getInstance()->getUri() . '" class="edit-instance btn-success small"><span class="icon-upload"></span> ' . __('Upload new media') . '</button>'; } $edit->setValue($value); $top[] = $edit; $bottom[] = $edit; $this->form->setActions($bottom, 'bottom'); $this->form->setActions($top, 'top'); }
protected function initElements() { parent::initElements(); /** @var \tao_helpers_form_elements_xhtml_Combobox $originalTestElement */ $originalTestElement = $this->getForm()->getElement(tao_helpers_Uri::encode(BookletClassService::PROPERTY_TEST)); $options = $originalTestElement->getOptions(); $formatElt = tao_helpers_form_FormFactory::getElement('test', 'Readonly'); $formatElt->setDescription(__('Selected test')); $formatElt->setValue(isset($options[$originalTestElement->getRawValue()]) ? $options[$originalTestElement->getRawValue()] : __('Test has been removed')); $downloadBtn = \tao_helpers_form_FormFactory::getElement('Download', 'Button'); $downloadBtn->setValue(__('Download') . ' PDF'); $downloadBtn->setIcon('icon-download'); $downloadBtn->addClass('btn-download btn-success small'); $this->getForm()->removeElement(tao_helpers_Uri::encode(BookletClassService::PROPERTY_TEST)); $this->getForm()->setActions(array_merge($this->form->getActions(), array($downloadBtn)), 'bottom'); $this->getForm()->addElement($formatElt); }
protected function initElements() { parent::initElements(); $maxExecElt = $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_MAXEXEC_PROP)); if (!is_null($maxExecElt)) { $maxExecElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('Integer', array('min' => 1)))); $this->form->addElement($maxExecElt); } $periodEndElt = $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_END_PROP)); if (!is_null($periodEndElt)) { $periodEndElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('DateTime', array('comparator' => '>=', 'datetime2_ref' => $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_START_PROP)))))); $this->form->addElement($periodEndElt); } $resultServerElt = $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_RESULTSERVER_PROP)); if (!is_null($resultServerElt)) { $resultServerElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'))); $this->form->addElement($resultServerElt); } }
/** * Short description of method initElements * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function initElements() { parent::initElements(); $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_URL)); $ele->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Url'))); $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE)); $ele->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED)); //prevent having neither enabled or disabled selected if (is_null($ele->getValue())) { $ele->setValue(tao_helpers_Uri::encode(GENERIS_FALSE)); } $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_LOGIN)); $ele->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH)); $ele->setHelp(__('Path to the local working copy, it is where your local version of your versioned Resource will be stored. ') . '/path/to/the/local/working_copy'); $ele->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); }
public function initElements() { parent::initElements(); $formatElt = tao_helpers_form_FormFactory::getElement('anonymousClass', 'Hidden'); $formatElt->setValue(tao_helpers_Uri::encode(BookletClassService::PROPERTY_ANONYMOUS)); $this->getForm()->addElement($formatElt); $testElement = $this->getForm()->getElement(tao_helpers_Uri::encode(BookletClassService::PROPERTY_TEST)); if (!count($testElement->getOptions())) { throw new \taoSimpleDelivery_actions_form_NoTestsException(); } $anonymousElm = $this->getForm()->getElement(tao_helpers_Uri::encode(BookletClassService::PROPERTY_ANONYMOUS)); $anonymousElm->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $testElement->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $createElt = \tao_helpers_form_FormFactory::getElement('create', 'Button'); $createElt->setValue(__('Generate')); $createElt->setIcon("icon-play"); $createElt->addClass("form-submitter btn-success small"); $this->form->setActions(array($createElt), 'bottom'); }
/** * (non-PHPdoc) * @see tao_actions_form_Instance::initElements() */ protected function initElements() { parent::initElements(); $elementId = tao_helpers_Uri::encode(TAO_ITEM_MODEL_PROPERTY); $ele = $this->form->getElement($elementId); $ele->feed(); $modelUri = $ele->getEvaluatedValue(); if (empty($modelUri)) { // remove deprecated models $statusProperty = new core_kernel_classes_Property(TAO_ITEM_MODEL_STATUS_PROPERTY); $options = array(); foreach ($ele->getOptions() as $optUri => $optLabel) { $model = new core_kernel_classes_Resource(tao_helpers_Uri::decode($optUri)); $status = $model->getOnePropertyValue($statusProperty); if (!is_null($status) && $status->getUri() != TAO_ITEM_MODEL_STATUS_DEPRECATED) { $options[$optUri] = $optLabel; } } $ele->setOptions($options); if (count($options) === 1) { reset($options); $ele->setValue(key($options)); } } else { // replace radio with hidden element $this->form->removeElement($elementId); $itemModelElt = tao_helpers_form_FormFactory::getElement($elementId, 'Hidden'); $itemModelElt->setValue($modelUri); $this->form->addElement($itemModelElt); // display model label $model = new core_kernel_classes_Resource($modelUri); $itemModelLabelElt = tao_helpers_form_FormFactory::getElement('itemModelLabel', 'Label'); $itemModelLabelElt->setDescription(__('Item Model')); $itemModelLabelElt->setValue($model->getLabel()); $this->form->addElement($itemModelLabelElt); } }
public function editInstance() { $clazz = $this->getCurrentClass(); $instance = $this->getCurrentInstance(); $myFormContainer = new tao_actions_form_Instance($clazz, $instance); $myForm = $myFormContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $values = $myForm->getValues(); // save properties $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($instance); $instance = $binder->bind($values); $message = __('Instance saved'); $this->setData('message', $message); $this->setData('reload', true); } } $this->setData('formTitle', __('Edit Instance')); $this->setData('myForm', $myForm->render()); $this->setView('form.tpl', 'tao'); }
/** * Edit a delivery instance * @return void */ public function editResultServer() { $clazz = $this->getCurrentClass(); $resultServer = $this->getCurrentResultServer(); $formContainer = new tao_actions_form_Instance($clazz, $resultServer); $myForm = $formContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($resultServer); $resultServer = $binder->bind($myForm->getValues()); $this->setData("selectNode", tao_helpers_Uri::encode($resultServer->getUri())); $this->setData('message', __('Result Server saved')); $this->setData('reload', true); } } $this->setSessionAttribute("showNodeUri", tao_helpers_Uri::encode($resultServer->getUri())); $this->setData('formTitle', __('Edit ResultServer')); $this->setData('myForm', $myForm->render()); $this->setView('form_resultserver.tpl'); }
/** * Short description of method initElements * * @access protected * @author Joel Bout, <*****@*****.**> * @return mixed */ protected function initElements() { if (!isset($this->options['mode'])) { throw new Exception("Please set a mode into container options "); } parent::initElements(); //login field $loginElement = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_LOGIN)); $loginElement->setDescription($loginElement->getDescription() . ' *'); if ($this->options['mode'] == 'add') { $loginElement->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Callback', array('object' => tao_models_classes_UserService::singleton(), 'method' => 'loginAvailable', 'message' => __('This Login is already in use'))))); } else { $loginElement->setAttributes(array('readonly' => 'readonly', 'disabled' => 'disabled')); } //set default lang to the languages fields $langService = tao_models_classes_LanguageService::singleton(); $dataLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_DEFLG)); $dataLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $dataLangElt->setDescription($dataLangElt->getDescription() . ' *'); $dataUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA); $dataOptions = array(); foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) { $dataOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel(); } $dataLangElt->setOptions($dataOptions); $uiLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_UILG)); $uiLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $uiLangElt->setDescription($uiLangElt->getDescription() . ' *'); $guiUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI); $guiOptions = array(); foreach ($langService->getAvailableLanguagesByUsage($guiUsage) as $lang) { $guiOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel(); } $uiLangElt->setOptions($guiOptions); // roles field $property = new core_kernel_classes_Property(PROPERTY_USER_ROLES); $roles = $property->getRange()->getInstances(true); $rolesOptions = array(); foreach ($roles as $r) { $rolesOptions[tao_helpers_Uri::encode($r->getUri())] = $r->getLabel(); } asort($rolesOptions); $rolesElt = $this->form->getElement(tao_helpers_Uri::encode($property->getUri())); $rolesElt->setDescription($rolesElt->getDescription() . ' *'); $rolesElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $rolesElt->setOptions($rolesOptions); // password field $this->form->removeElement(tao_helpers_Uri::encode(PROPERTY_USER_PASSWORD)); if ($this->options['mode'] == 'add') { $pass1Element = tao_helpers_form_FormFactory::getElement('password1', 'Hiddenbox'); $pass1Element->setDescription(__('Password *')); $pass1Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3)))); $this->form->addElement($pass1Element); $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox'); $pass2Element->setDescription(__('Repeat password *')); $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element)))); $this->form->addElement($pass2Element); } else { if (helpers_PlatformInstance::isDemo()) { $warning = tao_helpers_form_FormFactory::getElement('warningpass', 'Label'); $warning->setValue(__('Unable to change passwords in demo mode')); $this->form->addElement($warning); $this->form->createGroup("pass_group", __("Change the password"), array('warningpass')); } else { $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox'); $pass2Element->setDescription(__('New password')); $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3)))); $this->form->addElement($pass2Element); $pass3Element = tao_helpers_form_FormFactory::getElement('password3', 'Hiddenbox'); $pass3Element->setDescription(__('Repeat new password')); $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element)))); $this->form->addElement($pass3Element); $this->form->createGroup("pass_group", __("Change the password"), array('password1', 'password2', 'password3')); if (empty($_POST[$pass2Element->getName()]) && empty($_POST[$pass3Element->getName()])) { $pass2Element->setForcedValid(); $pass3Element->setForcedValid(); } } } /**/ }
protected function initForm() { parent::initForm(); $this->form->setActions(array(), 'top'); }