PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Widget/Block/Adminhtml/Widget/Instance/Edit/Tab/Settings.php

https://github.com/gryzz/crystal_magento
PHP | 196 lines | 96 code | 17 blank | 83 comment | 0 complexity | ecf8150f88483eb84c8db964a48697ea 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@magentocommerce.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.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Widget
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Widget Instance Settings tab block
  28. *
  29. * @category Mage
  30. * @package Mage_Widget
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Settings
  34. extends Mage_Adminhtml_Block_Widget_Form
  35. implements Mage_Adminhtml_Block_Widget_Tab_Interface
  36. {
  37. protected function _construct()
  38. {
  39. parent::_construct();
  40. $this->setActive(true);
  41. }
  42. /**
  43. * Prepare label for tab
  44. *
  45. * @return string
  46. */
  47. public function getTabLabel()
  48. {
  49. return Mage::helper('widget')->__('Settings');
  50. }
  51. /**
  52. * Prepare title for tab
  53. *
  54. * @return string
  55. */
  56. public function getTabTitle()
  57. {
  58. return Mage::helper('widget')->__('Settings');
  59. }
  60. /**
  61. * Returns status flag about this tab can be showen or not
  62. *
  63. * @return true
  64. */
  65. public function canShowTab()
  66. {
  67. return !(bool)$this->getWidgetInstance()->isCompleteToCreate();
  68. }
  69. /**
  70. * Returns status flag about this tab hidden or not
  71. *
  72. * @return true
  73. */
  74. public function isHidden()
  75. {
  76. return false;
  77. }
  78. /**
  79. * Getter
  80. *
  81. * @return Mage_Widget_Model_Widget_Instance
  82. */
  83. public function getWidgetInstance()
  84. {
  85. return Mage::registry('current_widget_instance');
  86. }
  87. /**
  88. * Prepare form before rendering HTML
  89. *
  90. * @return Mage_Widget_Block_Adminhtml_Widget_Instance_Edit_Tab_Settings
  91. */
  92. protected function _prepareForm()
  93. {
  94. $widgetInstance = $this->getWidgetInstance();
  95. $form = new Varien_Data_Form(array(
  96. 'id' => 'edit_form',
  97. 'action' => $this->getData('action'),
  98. 'method' => 'post'
  99. ));
  100. $fieldset = $form->addFieldset('base_fieldset',
  101. array('legend'=>Mage::helper('widget')->__('Settings'))
  102. );
  103. $this->_addElementTypes($fieldset);
  104. $fieldset->addField('type', 'select', array(
  105. 'name' => 'type',
  106. 'label' => Mage::helper('widget')->__('Type'),
  107. 'title' => Mage::helper('widget')->__('Type'),
  108. 'class' => '',
  109. 'values' => $this->getTypesOptionsArray()
  110. ));
  111. $fieldset->addField('package_theme', 'select', array(
  112. 'name' => 'package_theme',
  113. 'label' => Mage::helper('widget')->__('Design Package/Theme'),
  114. 'title' => Mage::helper('widget')->__('Design Package/Theme'),
  115. 'required' => false,
  116. 'values' => $this->getPackegeThemeOptionsArray()
  117. ));
  118. $continueButton = $this->getLayout()
  119. ->createBlock('adminhtml/widget_button')
  120. ->setData(array(
  121. 'label' => Mage::helper('widget')->__('Continue'),
  122. 'onclick' => "setSettings('".$this->getContinueUrl()."', 'type', 'package_theme')",
  123. 'class' => 'save'
  124. ));
  125. $fieldset->addField('continue_button', 'note', array(
  126. 'text' => $continueButton->toHtml(),
  127. ));
  128. $this->setForm($form);
  129. return parent::_prepareForm();
  130. }
  131. /**
  132. * Return url for continue button
  133. *
  134. * @return string
  135. */
  136. public function getContinueUrl()
  137. {
  138. return $this->getUrl('*/*/*', array(
  139. '_current' => true,
  140. 'type' => '{{type}}',
  141. 'package_theme' => '{{package_theme}}'
  142. ));
  143. }
  144. /**
  145. * Retrieve array (widget_type => widget_name) of available widgets
  146. *
  147. * @return array
  148. */
  149. public function getTypesOptionsArray()
  150. {
  151. $widgets = $this->getWidgetInstance()->getWidgetsOptionArray();
  152. array_unshift($widgets, array(
  153. 'value' => '',
  154. 'label' => Mage::helper('widget')->__('-- Please Select --')
  155. ));
  156. return $widgets;
  157. }
  158. /**
  159. * User-defined widgets sorting by Name
  160. *
  161. * @param array $a
  162. * @param array $b
  163. * @return boolean
  164. */
  165. protected function _sortWidgets($a, $b)
  166. {
  167. return strcmp($a["label"], $b["label"]);
  168. }
  169. /**
  170. * Retrieve package/theme options array
  171. *
  172. * @return array
  173. */
  174. public function getPackegeThemeOptionsArray()
  175. {
  176. return Mage::getModel('core/design_source_design')
  177. ->setIsFullLabel(true)->getAllOptions(true);
  178. }
  179. }