00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_Block_Widget_Form_Container extends Mage_Adminhtml_Block_Widget_Container
00036 {
00037 protected $_objectId = 'id';
00038 protected $_formScripts = array();
00039 protected $_formInitScripts = array();
00040 protected $_mode = 'edit';
00041 protected $_blockGroup = 'adminhtml';
00042
00043 public function __construct()
00044 {
00045 parent::__construct();
00046
00047 if (!$this->hasData('template')) {
00048 $this->setTemplate('widget/form/container.phtml');
00049 }
00050
00051 $this->_addButton('back', array(
00052 'label' => Mage::helper('adminhtml')->__('Back'),
00053 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
00054 'class' => 'back',
00055 ), -1);
00056 $this->_addButton('reset', array(
00057 'label' => Mage::helper('adminhtml')->__('Reset'),
00058 'onclick' => 'setLocation(window.location.href)',
00059 ), -1);
00060
00061 $objId = $this->getRequest()->getParam($this->_objectId);
00062
00063 if (! empty($objId)) {
00064 $this->_addButton('delete', array(
00065 'label' => Mage::helper('adminhtml')->__('Delete'),
00066 'class' => 'delete',
00067 'onclick' => 'deleteConfirm(\''. Mage::helper('adminhtml')->__('Are you sure you want to do this?')
00068 .'\', \'' . $this->getDeleteUrl() . '\')',
00069 ));
00070 }
00071
00072 $this->_addButton('save', array(
00073 'label' => Mage::helper('adminhtml')->__('Save'),
00074 'onclick' => 'editForm.submit();',
00075 'class' => 'save',
00076 ), 1);
00077 }
00078
00079 protected function _prepareLayout()
00080 {
00081 if ($this->_blockGroup && $this->_controller && $this->_mode) {
00082 $this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'));
00083 }
00084 return parent::_prepareLayout();
00085 }
00086
00087
00088
00089
00090
00091
00092 public function getBackUrl()
00093 {
00094 return $this->getUrl('*
00095
00096
00097
00098
00099 */delete', array($this->_objectId => $this->getRequest()->getParam($this->_objectId)));
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109 public function getSaveUrl()
00110 {
00111 return $this->getFormActionUrl();
00112 }
00113
00114
00115
00116
00117
00118
00119 public function getFormActionUrl()
00120 {
00121 if ($this->hasFormActionUrl()) {
00122 return $this->getData('form_action_url');
00123 }
00124 return $this->getUrl('*/' . $this->_controller . '/save');
00125 }
00126
00127 public function getFormHtml()
00128 {
00129 $this->getChild('form')->setData('action', $this->getSaveUrl());
00130 return $this->getChildHtml('form');
00131 }
00132
00133 public function getFormInitScripts()
00134 {
00135 if ( !empty($this->_formInitScripts) && is_array($this->_formInitScripts) ) {
00136 return '<script type="text/javascript">' . implode("\n", $this->_formInitScripts) . '</script>';
00137 }
00138 return '';
00139 }
00140
00141 public function getFormScripts()
00142 {
00143 if ( !empty($this->_formScripts) && is_array($this->_formScripts) ) {
00144 return '<script type="text/javascript">' . implode("\n", $this->_formScripts) . '</script>';
00145 }
00146 return '';
00147 }
00148
00149 public function getHeaderWidth()
00150 {
00151 return '';
00152 }
00153
00154 public function getHeaderCssClass()
00155 {
00156 return 'icon-head head-' . strtr($this->_controller, '_', '-');
00157 }
00158
00159 public function getHeaderHtml()
00160 {
00161 return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 public function setDataObject($object)
00171 {
00172 $this->getChild('form')->setDataObject($object);
00173 return $this->setData('data_object', $object);
00174 }
00175
00176 }