1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form
35: extends Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form
36: {
37: 38: 39: 40: 41: 42:
43: protected function _prepareForm()
44: {
45: $model = Mage::registry('current_message');
46:
47: if ($model->getStatus() == Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) {
48: $this->_fieldsEnabled = true;
49: } else {
50: $this->_fieldsEnabled = false;
51: }
52:
53: parent::_prepareForm();
54:
55: if (null !== Mage::registry('current_template')) {
56: $templateModel = Mage::registry('current_template');
57: } else {
58: $templateModel = Mage::getModel('xmlconnect/template')->load($model->getTemplateId());
59: }
60:
61: $fieldset = $this->getForm()->addFieldset(
62: "message_settings",
63: array('legend' => $this->__('Message Settings')),
64: '^'
65: );
66:
67: if ($model->getId()) {
68: $fieldset->addField('message_id', 'hidden', array(
69: 'name' => 'message_id'
70: ));
71: }
72:
73:
74: $model->setExecTime(Mage::getSingleton('core/date')->date(null, $model->getExecTime()));
75:
76:
77: $sovereignField = $fieldset->addField('type', 'select', array(
78: 'name' => 'type',
79: 'values' => Mage::helper('xmlconnect')->getMessageTypeOptions(),
80: 'label' => $this->__('Message Type'),
81: 'title' => $this->__('Message Type'),
82: 'disabled' => !$this->_fieldsEnabled,
83: 'required' => true,
84: ));
85:
86: $fieldset->addField('exec_time', 'date', array(
87: 'name' => 'exec_time',
88: 'format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
89: 'label' => $this->__('Start Date'),
90: 'time' => true,
91: 'title' => $this->__('Start Date'),
92: 'image' => $this->getSkinUrl('images/grid-cal.gif'),
93: 'note' => $this->__('If leave this field empty, the message will be sent immediately'),
94: 'disabled' => !$this->_fieldsEnabled,
95: 'required' => false,
96: ));
97:
98: $this->_addElementTypes($fieldset);
99:
100:
101: if (isset($this->_dependentFields['message_title']) || isset($this->_dependentFields['content'])) {
102: $dependenceBlock = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence');
103:
104: $dependenceBlock->addFieldMap(
105: $this->_dependentFields['message_title']->getHtmlId(),
106: $this->_dependentFields['message_title']->getName()
107: )
108: ->addFieldMap(
109: $this->_dependentFields['content']->getHtmlId(),
110: $this->_dependentFields['content']->getName()
111: )
112: ->addFieldMap(
113: $sovereignField->getHtmlId(),
114: $sovereignField->getName()
115: );
116:
117: if (!empty($this->_dependentFields['message_title'])) {
118: $dependenceBlock->addFieldDependence(
119: $this->_dependentFields['message_title']->getName(),
120: $sovereignField->getName(),
121: Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL
122: );
123:
124: if (!$this->_fieldsEnabled) {
125: $this->_dependentFields['message_title']->setReadonly(true, true);
126: }
127: }
128:
129: if (!empty($this->_dependentFields['content'])) {
130: $dependenceBlock->addFieldDependence(
131: $this->_dependentFields['content']->getName(),
132: $sovereignField->getName(),
133: Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL
134: );
135:
136: if (!$this->_fieldsEnabled) {
137: $this->_dependentFields['content']->setReadonly(true, true);
138: }
139: }
140: $this->setChild('form_after', $dependenceBlock);
141: }
142:
143: if (!$model->getName()) {
144: $model->setName($templateModel->getName());
145: }
146: if (!$model->getPushTitle()) {
147: $model->setPushTitle($templateModel->getPushTitle());
148: }
149: if (!$model->getMessageTitle()) {
150: $model->setMessageTitle($templateModel->getMessageTitle());
151: }
152: if (!$model->getContent()) {
153: $model->setContent($templateModel->getContent());
154: }
155: if (!$model->getTemplateId()) {
156: $model->setTemplateId($templateModel->getId());
157: }
158: $model->setMessageId($model->getId());
159: $model->setData('app_code', $templateModel->getData('app_code'));
160:
161: $this->getForm()->setAction($this->getUrl('*/*/saveMessage'));
162: $this->getForm()->setValues($model->getData());
163:
164: $this->setForm($this->getForm());
165: }
166: }
167: