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 class Mage_Adminhtml_Block_Widget_Container extends Mage_Adminhtml_Block_Template
00035 {
00036 
00037 
00038 
00039 
00040 
00041 
00042     protected $_controller = 'empty';
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050     protected $_buttons = array(
00051         -1  => array(),
00052         0   => array(),
00053         1   => array(),
00054     );
00055 
00056 
00057 
00058 
00059 
00060 
00061     protected $_headerText = 'Container Widget Header';
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072     protected function _addButton($id, $data, $level = 0, $sortOrder = 100, $area = 'header')
00073     {
00074         if (!isset($this->_buttons[$level])) {
00075             $this->_buttons[$level] = array();
00076         }
00077         $this->_buttons[$level][$id] = $data;
00078         $this->_buttons[$level][$id]['area'] = $area;
00079         return $this;
00080     }
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088     protected function _removeButton($id)
00089     {
00090         foreach ($this->_buttons as $level => $buttons) {
00091             if (isset($buttons[$id])) {
00092                 unset($this->_buttons[$level][$id]);
00093             }
00094         }
00095         return $this;
00096     }
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104     public function removeButton($id)
00105     {
00106         return $this->_removeButton($id);
00107     }
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117     protected function _updateButton($id, $key=null, $data)
00118     {
00119         foreach ($this->_buttons as $level => $buttons) {
00120             if (isset($buttons[$id])) {
00121                 if (!empty($key)) {
00122                     if ($child = $this->getChild($id . '_button')) {
00123                         $child->setData($key, $data);
00124                     }
00125                     if ('level' == $key) {
00126                         $this->_buttons[$data][$id] = $this->_buttons[$level][$id];
00127                         unset($this->_buttons[$level][$id]);
00128                     } else {
00129                         $this->_buttons[$level][$id][$key] = $data;
00130                     }
00131                 } else {
00132                     $this->_buttons[$level][$id] = $data;
00133                 }
00134                 break;
00135             }
00136         }
00137         return $this;
00138     }
00139 
00140     protected function _prepareLayout()
00141     {
00142         foreach ($this->_buttons as $level => $buttons) {
00143             foreach ($buttons as $id => $data) {
00144                 $this->setChild($id . '_button', $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data));
00145             }
00146         }
00147         return parent::_prepareLayout();
00148     }
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156     public function getButtonsHtml($area = null)
00157     {
00158         $out = '';
00159         foreach ($this->_buttons as $level => $buttons) {
00160             foreach ($buttons as $id => $data) {
00161                 if ($area && isset($data['area']) && ($area != $data['area'])) {
00162                     continue;
00163                 }
00164                 $out .= $this->getChildHtml($id . '_button');
00165             }
00166         }
00167         return $out;
00168     }
00169 
00170 
00171 
00172 
00173 
00174 
00175     public function getHeaderText()
00176     {
00177         return $this->_headerText;
00178     }
00179 
00180 
00181 
00182 
00183 
00184 
00185     public function getHeaderCssClass()
00186     {
00187         return 'head-' . strtr($this->_controller, '_', '-');
00188     }
00189 
00190 
00191 
00192 
00193 
00194 
00195     public function getHeaderHtml()
00196     {
00197         return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
00198     }
00199 
00200 
00201 
00202 
00203 
00204 
00205     public function hasFooterButtons()
00206     {
00207         foreach ($this->_buttons as $level => $buttons) {
00208             foreach ($buttons as $id => $data) {
00209                 if (isset($data['area']) && ('footer' == $data['area'])) {
00210                     return true;
00211                 }
00212             }
00213         }
00214         return false;
00215     }
00216 
00217 
00218 
00219 
00220 
00221 
00222     protected function _toHtml()
00223     {
00224         Mage::dispatchEvent('adminhtml_widget_container_html_before', array('block' => $this));
00225         return parent::_toHtml();
00226     }
00227 }