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_Adminhtml_Block_Cms_Block_Widget_Chooser extends Mage_Adminhtml_Block_Widget_Grid
35: {
36: 37: 38: 39: 40:
41: public function __construct($arguments=array())
42: {
43: parent::__construct($arguments);
44: $this->setDefaultSort('block_identifier');
45: $this->setDefaultDir('ASC');
46: $this->setUseAjax(true);
47: $this->setDefaultFilter(array('chooser_is_active' => '1'));
48: }
49:
50: 51: 52: 53: 54: 55:
56: public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element)
57: {
58: $uniqId = Mage::helper('core')->uniqHash($element->getId());
59: $sourceUrl = $this->getUrl('*/cms_block_widget/chooser', array('uniq_id' => $uniqId));
60:
61: $chooser = $this->getLayout()->createBlock('widget/adminhtml_widget_chooser')
62: ->setElement($element)
63: ->setTranslationHelper($this->getTranslationHelper())
64: ->setConfig($this->getConfig())
65: ->setFieldsetId($this->getFieldsetId())
66: ->setSourceUrl($sourceUrl)
67: ->setUniqId($uniqId);
68:
69:
70: if ($element->getValue()) {
71: $block = Mage::getModel('cms/block')->load($element->getValue());
72: if ($block->getId()) {
73: $chooser->setLabel($block->getTitle());
74: }
75: }
76:
77: $element->setData('after_element_html', $chooser->toHtml());
78: return $element;
79: }
80:
81: 82: 83: 84: 85:
86: public function getRowClickCallback()
87: {
88: $chooserJsObject = $this->getId();
89: $js = '
90: function (grid, event) {
91: var trElement = Event.findElement(event, "tr");
92: var blockId = trElement.down("td").innerHTML.replace(/^\s+|\s+$/g,"");
93: var blockTitle = trElement.down("td").next().innerHTML;
94: '.$chooserJsObject.'.setElementValue(blockId);
95: '.$chooserJsObject.'.setElementLabel(blockTitle);
96: '.$chooserJsObject.'.close();
97: }
98: ';
99: return $js;
100: }
101:
102: 103: 104: 105: 106:
107: protected function _prepareCollection()
108: {
109: $collection = Mage::getModel('cms/block')->getCollection();
110:
111: $this->setCollection($collection);
112: return parent::_prepareCollection();
113: }
114:
115: 116: 117: 118: 119:
120: protected function _prepareColumns()
121: {
122: $this->addColumn('chooser_id', array(
123: 'header' => Mage::helper('cms')->__('ID'),
124: 'align' => 'right',
125: 'index' => 'block_id',
126: 'width' => 50
127: ));
128:
129: $this->addColumn('chooser_title', array(
130: 'header' => Mage::helper('cms')->__('Title'),
131: 'align' => 'left',
132: 'index' => 'title',
133: ));
134:
135: $this->addColumn('chooser_identifier', array(
136: 'header' => Mage::helper('cms')->__('Identifier'),
137: 'align' => 'left',
138: 'index' => 'identifier'
139: ));
140:
141:
142: $this->addColumn('chooser_is_active', array(
143: 'header' => Mage::helper('cms')->__('Status'),
144: 'index' => 'is_active',
145: 'type' => 'options',
146: 'options' => array(
147: 0 => Mage::helper('cms')->__('Disabled'),
148: 1 => Mage::helper('cms')->__('Enabled')
149: ),
150: ));
151:
152: return parent::_prepareColumns();
153: }
154:
155: public function getGridUrl()
156: {
157: return $this->getUrl('*/cms_block_widget/chooser', array('_current' => true));
158: }
159: }
160: