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