dataObj->create(Qs_Request::getGetValue('formId'), Qs_Request::getGetValue('formType')); $this->dataObj->initData(); $this->_addItem($this->getItem('edit')); $this->_displayJson(array('html' => $this->doc->fetch(), 'id' => $this->dataObj->getPrimaryKey())); } protected function _doGetAjax() { $this->_addItem($this->getItem('edit')); return $this; } public function getItem($action = 'view') { $item = $this->dataObj->getData(); $item['tpl'] = $this->getTemplate('view.tpl'); $item['id'] = $this->dataObj->getPrimaryKey(); $item['action'] = $action; $item['type'] = App_FormBuilder_Element_Obj::$types[$item['typeId']]; return $item; } protected function _doPropertiesAjax() { $form = $this->_getPropertiesForm(); $this->dataObj->initData(); $form->setDefaults($this->dataObj->getData()); $this->_renderForm($form, 'propertyForm.tpl'); return $this; } protected function _getPropertiesForm() { $form = $this->_getBaseForm(); $form->addElementPrefixPath('App_FormBuilder_Element_Validate', 'App/FormBuilder/Element/Validate/', Zend_Form_Element::VALIDATE); $this->_bindFormFields($form); $this->_bindFormButtons($form); return $form; } protected function _bindFormFields(Qs_Form $form) { $form->addElement('hidden', 'action', array('value' => 'save')); $form->addElement('hidden', 'elementId', array('value' => $this->dataObj->getPrimaryKey())); $properties = $this->dataObj->getProperties(); foreach ($properties as $property) { $options = Zend_Json::decode($property['options']); $options['label'] = $property['label']; $form->addElement($property['type'], $property['alias'], $options); } if ($this->_getData('label', $this->getFormDefaults('label'))) { $form->labelWidth->setRequired(); $validators = $form->labelWidth->getValidators(); $notEmptyValidator = new Zend_Validate_NotEmpty(); $notEmptyValidator->zfBreakChainOnFailure = true; $notEmptyValidator->setMessage(self::LABEL_WIDTH_REQUIRED, Zend_Validate_NotEmpty::IS_EMPTY); $form->labelWidth->setValidators(array('Zend_Validate_NotEmpty' => $notEmptyValidator) + $validators); } if ($form->getElement('isDecimal') && $form->getElement('defaultValue') && 'y' === $this->_getData('isDecimal')) { $form->getElement('defaultValue')->addValidator('Float'); } return $this; } protected function _bindFormButtons(Qs_Form $form) { $form->addElement('submit', 'btnSubmit', array( 'label' => 'Save', 'attribs' => array('class' => 'btn'), 'decorators' => array('ViewHelper')) ); $form->addElement('button', 'btnCancel', array( 'label' => 'Cancel', 'attribs' => array('class' => 'btn', 'onclick' => '$.fancybox.close();'), 'decorators' => array('ViewHelper')) ); $decorators = array( 'FormElements', array('decorator' => 'HtmlTag', 'options' => array('tag' => 'div')), 'Fieldset', 'DtDdWrapper'); $form->addDisplayGroup(array('btnSubmit', 'btnCancel'), 'submitGroup', array('decorators' => $decorators)); return $this; } protected function _doSaveAjax() { $form = $this->_getPropertiesForm(); $result = $this->_getValidateAjaxResult($form); if ($result['isValid']) { $this->_initFromForm($form); $this->dataObj->setPrimaryKey($_REQUEST['elementId']); $this->dataObj->save(); } $this->_displayJson($result); } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); $data['name'] = $data['propertyName']; $this->dataObj->initFromForm($data); return $this; } protected function _doSave() { $this->_doSaveAjax(); } }