_idCategory = (int)Qs_Request::getRequestValue( 'idCategory', reset(array_keys($this->dataObj->getCategories())) // дефолтна категорія ); $this->setDataObj(new App_Settings_Obj(array('idCategory' => $this->_idCategory, 'suMode' => $this->_doc->getAuth()->getSuMode()))); parent::_init(); $this->_setMessage('%itemsName% have been updated', self::MSG_UPDATED); } protected function _bindFormFields($form) { $form->addElement('hidden', 'idCategory', array('value' => $this->_idCategory)); $fields = $this->dataObj->getList(); foreach ($fields as $field) { $field['fieldType'] = ucfirst($field['fieldType']); $options = $this->dataObj->getFieldOptions($field['name']); switch ($field['fieldType']) { case 'Emails': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'rows' => 5, 'description' => $field['description'], 'decorators' => array( array('Description', array('tag' => 'p', 'class' => 'description')), 'ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'dd', 'id' => $field['name'] . '-element')), array('Label', array('tag' => 'dt')) ) ); $form->addElement('textarea', $field['name'], array_merge($defaultOptions, $options)); $form->{$field['name']}->addValidator('EmailAddresses') ->addFilter('EmailAddresses'); $form->{$field['name']}->getDecorator('Label')->setOption('escape', false); break; case 'Select': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'size' => $options['size'], 'description' => $field['description'], 'multiple' => $options['multiple'] ); $form->addElement($field['fieldType'], $field['name'], array_merge($defaultOptions, $options)); break; case 'HtmlEditor': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'description' => $field['description'] ); $form->addElement($field['fieldType'], $field['name'], array_merge($defaultOptions, $options)); break; case 'Header': $defaultOptions = array('label' => $field['label']); $form->addElement($field['fieldType'], $field['name'], array_merge($defaultOptions, $options)); break; case 'Url': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'description' => $field['description'] ); $form->addElement('text', $field['name'], array_merge($defaultOptions, $options)); $form->{$field['name']}->addValidator('Url')->addFilter('StringTrim'); break; default: $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'description' => $field['description'] ); $form->addElement($field['fieldType'], $field['name'], array_merge($defaultOptions, $options)); break; } } return $this; } protected function _getEditForm() { $form = $this->_getBaseForm(); $form->setAjaxValidation(false); $form->setCancelUrl(Qs_Constant::get('BASE_URL_LANGUAGE') . '/' . Qs_Constant::get('CURRENT_PAGE') . '?action=cancel&idCategory=' . $this->_idCategory); $form->setEnctype(Qs_Form::ENCTYPE_MULTIPART); $this->_bindCategoryButtons($form); $this->_bindFormFields($form); $this->_bindFormButtons($form); $form->addElement('hidden', 'action', array('value' => 'update')); return $form; } protected function _bindCategoryButtons($form) { $categories = $this->_dataObj->getCategories(); if (is_array($categories) && count($categories) > 1) { $elements = array(); foreach ($categories as $id => $label) { $name = $this->_tabButtonPrefix . $id; $form->addElement('button', $name, array( 'label' => $label, 'attribs' => array('class' => 'settingsBtnTab' . (($this->_idCategory == $id) ? 'Active' : ''), 'onclick' => "try {document.location='" . BASE_URL . '/' . CURRENT_PAGE . '?idCategory=' . (int)$id . "'} catch(e) {};"), 'decorators' => array('ViewHelper'))); $elements[] = $name; } $decorators = array('FormElements'); $decorators[] = array('decorator' => 'HtmlTag', 'options' => array('tag' => 'div')); $decorators[] = 'Fieldset'; $decorators[] = 'DtDdWrapper'; $form->addDisplayGroup($elements, 'tabsGroup', array('decorators' => $decorators)); } return $this; } protected function _renderMainForm($form) { $this->_doc->addScript('js/lib/settings.js'); $this->_doc->addInitFunction('initSettingsForm', array($form->getId())); return parent::_renderMainForm($form); } protected function _getBackUrl($sessionName = null) { $categories = $this->_dataObj->getCategories(); $idCategory = 0; foreach (array_keys($categories) as $id) { $key = $this->_tabButtonPrefix . $id; if (array_key_exists($key, $_REQUEST)) { $idCategory = $id; break; } } if (!$idCategory) { $idCategory = $this->_idCategory; } $options = array('idCategory' => $idCategory); return $this->url($options); } }