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:
35: abstract class Mage_Adminhtml_Block_Sales_Order_Create_Form_Abstract
36: extends Mage_Adminhtml_Block_Sales_Order_Create_Abstract
37: {
38: 39: 40: 41: 42:
43: protected $_form;
44:
45: 46: 47: 48: 49: 50:
51: protected function _prepareLayout()
52: {
53: parent::_prepareLayout();
54:
55: Varien_Data_Form::setElementRenderer(
56: $this->getLayout()->createBlock('adminhtml/widget_form_renderer_element')
57: );
58: Varien_Data_Form::setFieldsetRenderer(
59: $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
60: );
61: Varien_Data_Form::setFieldsetElementRenderer(
62: $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
63: );
64:
65: return $this;
66: }
67:
68: 69: 70: 71: 72:
73: public function getForm()
74: {
75: if (is_null($this->_form)) {
76: $this->_form = new Varien_Data_Form();
77: $this->_prepareForm();
78: }
79:
80: return $this->_form;
81: }
82:
83: 84: 85: 86: 87:
88: abstract protected function _prepareForm();
89:
90: 91: 92: 93: 94:
95: protected function _getAdditionalFormElementTypes()
96: {
97: return array(
98: 'file' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_file'),
99: 'image' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_image'),
100: 'boolean' => Mage::getConfig()->getBlockClassName('adminhtml/customer_form_element_boolean'),
101: );
102: }
103:
104: 105: 106: 107: 108:
109: protected function _getAdditionalFormElementRenderers()
110: {
111: return array(
112: 'region' => $this->getLayout()->createBlock('adminhtml/customer_edit_renderer_region'),
113: );
114: }
115:
116: 117: 118: 119: 120: 121:
122: protected function _addAdditionalFormElementData(Varien_Data_Form_Element_Abstract $element)
123: {
124: return $this;
125: }
126:
127: 128: 129: 130: 131: 132: 133:
134: protected function _addAttributesToForm($attributes, Varien_Data_Form_Abstract $form)
135: {
136:
137: $types = $this->_getAdditionalFormElementTypes();
138: foreach ($types as $type => $className) {
139: $form->addType($type, $className);
140: }
141: $renderers = $this->_getAdditionalFormElementRenderers();
142:
143: foreach ($attributes as $attribute) {
144:
145: $attribute->setStoreId(Mage::getSingleton('adminhtml/session_quote')->getStoreId());
146: $inputType = $attribute->getFrontend()->getInputType();
147:
148: if ($inputType) {
149: $element = $form->addField($attribute->getAttributeCode(), $inputType, array(
150: 'name' => $attribute->getAttributeCode(),
151: 'label' => $this->__($attribute->getStoreLabel()),
152: 'class' => $attribute->getFrontend()->getClass(),
153: 'required' => $attribute->getIsRequired(),
154: ));
155: if ($inputType == 'multiline') {
156: $element->setLineCount($attribute->getMultilineCount());
157: }
158: $element->setEntityAttribute($attribute);
159: $this->_addAdditionalFormElementData($element);
160:
161: if (!empty($renderers[$attribute->getAttributeCode()])) {
162: $element->setRenderer($renderers[$attribute->getAttributeCode()]);
163: }
164:
165: if ($inputType == 'select' || $inputType == 'multiselect') {
166: $element->setValues($attribute->getFrontend()->getSelectOptions());
167: } else if ($inputType == 'date') {
168: $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
169: $element->setImage($this->getSkinUrl('images/grid-cal.gif'));
170: $element->setFormat($format);
171: }
172: }
173: }
174:
175: return $this;
176: }
177:
178: 179: 180: 181: 182:
183: public function getFormValues()
184: {
185: return array();
186: }
187: }
188: