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: class Mage_Adminhtml_Block_Widget_Form_Container extends Mage_Adminhtml_Block_Widget_Container
36: {
37: protected $_objectId = 'id';
38: protected $_formScripts = array();
39: protected $_formInitScripts = array();
40: protected $_mode = 'edit';
41: protected $_blockGroup = 'adminhtml';
42:
43: public function __construct()
44: {
45: parent::__construct();
46:
47: if (!$this->hasData('template')) {
48: $this->setTemplate('widget/form/container.phtml');
49: }
50:
51: $this->_addButton('back', array(
52: 'label' => Mage::helper('adminhtml')->__('Back'),
53: 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
54: 'class' => 'back',
55: ), -1);
56: $this->_addButton('reset', array(
57: 'label' => Mage::helper('adminhtml')->__('Reset'),
58: 'onclick' => 'setLocation(window.location.href)',
59: ), -1);
60:
61: $objId = $this->getRequest()->getParam($this->_objectId);
62:
63: if (! empty($objId)) {
64: $this->_addButton('delete', array(
65: 'label' => Mage::helper('adminhtml')->__('Delete'),
66: 'class' => 'delete',
67: 'onclick' => 'deleteConfirm(\''. Mage::helper('adminhtml')->__('Are you sure you want to do this?')
68: .'\', \'' . $this->getDeleteUrl() . '\')',
69: ));
70: }
71:
72: $this->_addButton('save', array(
73: 'label' => Mage::helper('adminhtml')->__('Save'),
74: 'onclick' => 'editForm.submit();',
75: 'class' => 'save',
76: ), 1);
77: }
78:
79: protected function _prepareLayout()
80: {
81: if ($this->_blockGroup && $this->_controller && $this->_mode) {
82: $this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'));
83: }
84: return parent::_prepareLayout();
85: }
86:
87: 88: 89: 90: 91:
92: public function getBackUrl()
93: {
94: return $this->getUrl('*/*/');
95: }
96:
97: public function getDeleteUrl()
98: {
99: return $this->getUrl('*/*/delete', array($this->_objectId => $this->getRequest()->getParam($this->_objectId)));
100: }
101:
102: 103: 104: 105: 106: 107: 108:
109: public function getSaveUrl()
110: {
111: return $this->getFormActionUrl();
112: }
113:
114: 115: 116: 117: 118:
119: public function getFormActionUrl()
120: {
121: if ($this->hasFormActionUrl()) {
122: return $this->getData('form_action_url');
123: }
124: return $this->getUrl('*/' . $this->_controller . '/save');
125: }
126:
127: public function getFormHtml()
128: {
129: $this->getChild('form')->setData('action', $this->getSaveUrl());
130: return $this->getChildHtml('form');
131: }
132:
133: public function getFormInitScripts()
134: {
135: if ( !empty($this->_formInitScripts) && is_array($this->_formInitScripts) ) {
136: return '<script type="text/javascript">' . implode("\n", $this->_formInitScripts) . '</script>';
137: }
138: return '';
139: }
140:
141: public function getFormScripts()
142: {
143: if ( !empty($this->_formScripts) && is_array($this->_formScripts) ) {
144: return '<script type="text/javascript">' . implode("\n", $this->_formScripts) . '</script>';
145: }
146: return '';
147: }
148:
149: public function ()
150: {
151: return '';
152: }
153:
154: public function ()
155: {
156: return 'icon-head head-' . strtr($this->_controller, '_', '-');
157: }
158:
159: public function ()
160: {
161: return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
162: }
163:
164: 165: 166: 167: 168: 169:
170: public function setDataObject($object)
171: {
172: $this->getChild('form')->setDataObject($object);
173: return $this->setData('data_object', $object);
174: }
175:
176: }
177: