PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php

https://bitbucket.org/eurofides2018/magento_1.9_patches
PHP | 191 lines | 116 code | 21 blank | 54 comment | 10 complexity | 4c3eea293197563bcc968d33bb7e120d 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. * Adminhtml form container block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Widget_Form_Container extends Mage_Adminhtml_Block_Widget_Container
  34. {
  35. protected $_objectId = 'id';
  36. protected $_formScripts = array();
  37. protected $_formInitScripts = array();
  38. protected $_mode = 'edit';
  39. protected $_blockGroup = 'adminhtml';
  40. public function __construct()
  41. {
  42. parent::__construct();
  43. if (!$this->hasData('template')) {
  44. $this->setTemplate('widget/form/container.phtml');
  45. }
  46. $this->_addButton('back', array(
  47. 'label' => Mage::helper('adminhtml')->__('Back'),
  48. 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
  49. 'class' => 'back',
  50. ), -1);
  51. $this->_addButton('reset', array(
  52. 'label' => Mage::helper('adminhtml')->__('Reset'),
  53. 'onclick' => 'setLocation(window.location.href)',
  54. ), -1);
  55. $objId = $this->getRequest()->getParam($this->_objectId);
  56. if (! empty($objId)) {
  57. $this->_addButton('delete', array(
  58. 'label' => Mage::helper('adminhtml')->__('Delete'),
  59. 'class' => 'delete',
  60. 'onclick' => 'deleteConfirm(\''
  61. . Mage::helper('core')->jsQuoteEscape(
  62. Mage::helper('adminhtml')->__('Are you sure you want to do this?')
  63. )
  64. .'\', \''
  65. . $this->getDeleteUrl()
  66. . '\')',
  67. ));
  68. }
  69. $this->_addButton('save', array(
  70. 'label' => Mage::helper('adminhtml')->__('Save'),
  71. 'onclick' => 'editForm.submit();',
  72. 'class' => 'save',
  73. ), 1);
  74. }
  75. protected function _prepareLayout()
  76. {
  77. if ($this->_blockGroup && $this->_controller && $this->_mode) {
  78. $this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup
  79. . '/'
  80. . $this->_controller
  81. . '_'
  82. . $this->_mode
  83. . '_form'
  84. )
  85. );
  86. }
  87. return parent::_prepareLayout();
  88. }
  89. /**
  90. * Get URL for back (reset) button
  91. *
  92. * @return string
  93. */
  94. public function getBackUrl()
  95. {
  96. return $this->getUrl('*/*/');
  97. }
  98. public function getDeleteUrl()
  99. {
  100. return $this->getUrl('*/*/delete', array(
  101. $this->_objectId => $this->getRequest()->getParam($this->_objectId),
  102. Mage_Core_Model_Url::FORM_KEY => $this->getFormKey()
  103. ));
  104. }
  105. /**
  106. * Get form save URL
  107. *
  108. * @deprecated
  109. * @see getFormActionUrl()
  110. * @return string
  111. */
  112. public function getSaveUrl()
  113. {
  114. return $this->getFormActionUrl();
  115. }
  116. /**
  117. * Get form action URL
  118. *
  119. * @return string
  120. */
  121. public function getFormActionUrl()
  122. {
  123. if ($this->hasFormActionUrl()) {
  124. return $this->getData('form_action_url');
  125. }
  126. return $this->getUrl('*/' . $this->_controller . '/save');
  127. }
  128. public function getFormHtml()
  129. {
  130. $this->getChild('form')->setData('action', $this->getSaveUrl());
  131. return $this->getChildHtml('form');
  132. }
  133. public function getFormInitScripts()
  134. {
  135. if ( !empty($this->_formInitScripts) && is_array($this->_formInitScripts) ) {
  136. return '<script type="text/javascript">' . implode("\n", $this->_formInitScripts) . '</script>';
  137. }
  138. return '';
  139. }
  140. public function getFormScripts()
  141. {
  142. if ( !empty($this->_formScripts) && is_array($this->_formScripts) ) {
  143. return '<script type="text/javascript">' . implode("\n", $this->_formScripts) . '</script>';
  144. }
  145. return '';
  146. }
  147. public function getHeaderWidth()
  148. {
  149. return '';
  150. }
  151. public function getHeaderCssClass()
  152. {
  153. return 'icon-head head-' . strtr($this->_controller, '_', '-');
  154. }
  155. public function getHeaderHtml()
  156. {
  157. return '<h3 class="' . $this->getHeaderCssClass() . '">' . $this->getHeaderText() . '</h3>';
  158. }
  159. /**
  160. * Set data object and pass it to form
  161. *
  162. * @param Varien_Object $object
  163. * @return Mage_Adminhtml_Block_Widget_Form_Container
  164. */
  165. public function setDataObject($object)
  166. {
  167. $this->getChild('form')->setDataObject($object);
  168. return $this->setData('data_object', $object);
  169. }
  170. }