PageRenderTime 26ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Cms/Page/Widget/Chooser.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 165 lines | 90 code | 16 blank | 59 comment | 2 complexity | e8014b546a7308ff53ac9eef20602bb0 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * CMS page chooser for Wysiwyg CMS widget
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Cms_Page_Widget_Chooser extends Mage_Adminhtml_Block_Widget_Grid
  34. {
  35. /**
  36. * Block construction, prepare grid params
  37. *
  38. * @param array $arguments Object data
  39. */
  40. public function __construct($arguments=array())
  41. {
  42. parent::__construct($arguments);
  43. //$this->setDefaultSort('name');
  44. $this->setUseAjax(true);
  45. $this->setDefaultFilter(array('chooser_is_active' => '1'));
  46. }
  47. /**
  48. * Prepare chooser element HTML
  49. *
  50. * @param Varien_Data_Form_Element_Abstract $element Form Element
  51. * @return Varien_Data_Form_Element_Abstract
  52. */
  53. public function prepareElementHtml(Varien_Data_Form_Element_Abstract $element)
  54. {
  55. $uniqId = Mage::helper('core')->uniqHash($element->getId());
  56. $sourceUrl = $this->getUrl('*/cms_page_widget/chooser', array('uniq_id' => $uniqId));
  57. $chooser = $this->getLayout()->createBlock('widget/adminhtml_widget_chooser')
  58. ->setElement($element)
  59. ->setTranslationHelper($this->getTranslationHelper())
  60. ->setConfig($this->getConfig())
  61. ->setFieldsetId($this->getFieldsetId())
  62. ->setSourceUrl($sourceUrl)
  63. ->setUniqId($uniqId);
  64. if ($element->getValue()) {
  65. $page = Mage::getModel('cms/page')->load((int)$element->getValue());
  66. if ($page->getId()) {
  67. $chooser->setLabel($page->getTitle());
  68. }
  69. }
  70. $element->setData('after_element_html', $chooser->toHtml());
  71. return $element;
  72. }
  73. /**
  74. * Grid Row JS Callback
  75. *
  76. * @return string
  77. */
  78. public function getRowClickCallback()
  79. {
  80. $chooserJsObject = $this->getId();
  81. $js = '
  82. function (grid, event) {
  83. var trElement = Event.findElement(event, "tr");
  84. var pageTitle = trElement.down("td").next().innerHTML;
  85. var pageId = trElement.down("td").innerHTML.replace(/^\s+|\s+$/g,"");
  86. '.$chooserJsObject.'.setElementValue(pageId);
  87. '.$chooserJsObject.'.setElementLabel(pageTitle);
  88. '.$chooserJsObject.'.close();
  89. }
  90. ';
  91. return $js;
  92. }
  93. /**
  94. * Prepare pages collection
  95. *
  96. * @return Mage_Adminhtml_Block_Widget_Grid
  97. */
  98. protected function _prepareCollection()
  99. {
  100. $collection = Mage::getModel('cms/page')->getCollection();
  101. /* @var $collection Mage_Cms_Model_Mysql4_Page_Collection */
  102. $collection->setFirstStoreFlag(true);
  103. $this->setCollection($collection);
  104. return parent::_prepareCollection();
  105. }
  106. /**
  107. * Prepare columns for pages grid
  108. *
  109. * @return Mage_Adminhtml_Block_Widget_Grid
  110. */
  111. protected function _prepareColumns()
  112. {
  113. $this->addColumn('chooser_id', array(
  114. 'header' => Mage::helper('cms')->__('ID'),
  115. 'align' => 'right',
  116. 'index' => 'page_id',
  117. 'width' => 50
  118. ));
  119. $this->addColumn('chooser_title', array(
  120. 'header' => Mage::helper('cms')->__('Title'),
  121. 'align' => 'left',
  122. 'index' => 'title',
  123. ));
  124. $this->addColumn('chooser_identifier', array(
  125. 'header' => Mage::helper('cms')->__('URL Key'),
  126. 'align' => 'left',
  127. 'index' => 'identifier'
  128. ));
  129. $this->addColumn('chooser_root_template', array(
  130. 'header' => Mage::helper('cms')->__('Layout'),
  131. 'index' => 'root_template',
  132. 'type' => 'options',
  133. 'options' => Mage::getSingleton('page/source_layout')->getOptions(),
  134. 'width' => '100',
  135. ));
  136. $this->addColumn('chooser_is_active', array(
  137. 'header' => Mage::helper('cms')->__('Status'),
  138. 'index' => 'is_active',
  139. 'type' => 'options',
  140. 'options' => Mage::getModel('cms/page')->getAvailableStatuses(),
  141. 'width' => '100',
  142. ));
  143. return parent::_prepareColumns();
  144. }
  145. public function getGridUrl()
  146. {
  147. return $this->getUrl('*/cms_page_widget/chooser', array('_current' => true));
  148. }
  149. }