dynamic form rendering for template
bootstrap datetime widget. jquery update is needed, testing with hosted jquery first.
This commit is contained in:
parent
c7b5592fa9
commit
46ecdf393d
11 changed files with 10512 additions and 69 deletions
|
@ -2,9 +2,9 @@
|
|||
|
||||
class Application_Form_EditHistoryItem extends Zend_Form
|
||||
{
|
||||
const VALIDATE_DATETIME_FORMAT = 'yyyy-MM-dd HH-mm-ss';
|
||||
const VALIDATE_DATETIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
||||
const VALIDATE_DATE_FORMAT = 'yyyy-MM-dd';
|
||||
const VALIDATE_TIME_FORMAT = 'HH-mm-ss';
|
||||
const VALIDATE_TIME_FORMAT = 'HH:mm:ss';
|
||||
|
||||
const ID_PREFIX = "his_item_";
|
||||
|
||||
|
@ -12,11 +12,13 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
const ITEM_CLASS = "class";
|
||||
const ITEM_ID_SUFFIX = "name";
|
||||
|
||||
const TEXT_INPUT_CLASS = "input_text";
|
||||
|
||||
private $formElTypes = array(
|
||||
TEMPLATE_DATE => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => "input_text"
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
|
@ -33,7 +35,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
TEMPLATE_TIME => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => "input_text"
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
|
@ -50,7 +52,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
TEMPLATE_DATETIME => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => "input_text"
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
|
@ -67,7 +69,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
TEMPLATE_STRING => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => "input_text"
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"filters" => array(
|
||||
"StringTrim"
|
||||
|
@ -87,7 +89,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
)
|
||||
),
|
||||
"attrs" => array(
|
||||
"class" => "input_text"
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"filters" => array(
|
||||
"Int"
|
||||
|
@ -96,7 +98,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
TEMPLATE_FLOAT => array(
|
||||
"class" => "Zend_Form_Element_Text",
|
||||
"attrs" => array(
|
||||
"class" => "input_text"
|
||||
"class" => self::TEXT_INPUT_CLASS
|
||||
),
|
||||
"validators" => array(
|
||||
array(
|
||||
|
@ -107,16 +109,69 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
);
|
||||
|
||||
public function init() {
|
||||
|
||||
$this->setDecorators(array(
|
||||
'PrepareElements',
|
||||
array('ViewScript', array('viewScript' => 'form/edit-history-item.phtml'))
|
||||
));
|
||||
|
||||
$history_id = new Zend_Form_Element_Hidden(self::ID_PREFIX.'id');
|
||||
$history_id->setValidators(array(
|
||||
new Zend_Validate_Int()
|
||||
));
|
||||
$history_id->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($history_id);
|
||||
|
||||
$starts = new Zend_Form_Element_Text(self::ID_PREFIX.'starts');
|
||||
$starts->setValidators(array(
|
||||
new Zend_Validate_Date(self::VALIDATE_DATETIME_FORMAT)
|
||||
));
|
||||
$starts->setAttrib('class', self::TEXT_INPUT_CLASS);
|
||||
$starts->setAttrib('data-format', self::VALIDATE_DATETIME_FORMAT);
|
||||
$starts->addFilter('StringTrim');
|
||||
$starts->setLabel(_('Start Time'));
|
||||
$starts->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($starts);
|
||||
|
||||
$ends = new Zend_Form_Element_Text(self::ID_PREFIX.'ends');
|
||||
$ends->setValidators(array(
|
||||
new Zend_Validate_Date(self::VALIDATE_DATETIME_FORMAT)
|
||||
));
|
||||
$ends->setAttrib('class', self::TEXT_INPUT_CLASS);
|
||||
$ends->setAttrib('data-format', self::VALIDATE_DATETIME_FORMAT);
|
||||
$ends->addFilter('StringTrim');
|
||||
$ends->setLabel(_('End Time'));
|
||||
$ends->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($ends);
|
||||
|
||||
$dynamic_attrs = new Zend_Form_SubForm();
|
||||
$this->addSubForm($dynamic_attrs, self::ID_PREFIX.'template');
|
||||
|
||||
// Add the submit button
|
||||
$this->addElement('button', 'his_item_save', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn his_item_save',
|
||||
'label' => _('Save'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
// Add the cancel button
|
||||
$this->addElement('button', 'his_item_cancel', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn his_item_cancel',
|
||||
'label' => _('Cancel'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function createFromTemplate($template) {
|
||||
|
||||
$templateSubForm = $this->getSubForm(self::ID_PREFIX.'template');
|
||||
|
||||
for ($i = 0, $len = count($template); $i < $len; $i++) {
|
||||
|
||||
$item = $template[$i];
|
||||
|
@ -170,41 +225,8 @@ class Application_Form_EditHistoryItem extends Zend_Form
|
|||
}
|
||||
}
|
||||
|
||||
$this->addElement($el);
|
||||
}
|
||||
|
||||
// Add the submit button
|
||||
$this->addElement('button', 'his_item_save', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn his_item_save',
|
||||
'label' => _('Save'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
// Add the cancel button
|
||||
$this->addElement('button', 'his_item_cancel', array(
|
||||
'ignore' => true,
|
||||
'class' => 'btn his_item_cancel',
|
||||
'label' => _('Cancel'),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addDisplayGroup(
|
||||
array(
|
||||
'his_item_save',
|
||||
'his_item_cancel'
|
||||
),
|
||||
'submitButtons',
|
||||
array(
|
||||
'decorators' => array(
|
||||
'FormElements',
|
||||
'DtDdWrapper'
|
||||
)
|
||||
)
|
||||
);
|
||||
$el->setDecorators(array('ViewHelper'));
|
||||
$templateSubForm->addElement($el);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue