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_Api2
23: * @copyright Copyright (c) 2012 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: /**
28: * Block for rendering buttons
29: *
30: * @category Mage
31: * @package Mage_Api2
32: * @author Magento Core Team <core@magentocommerce.com>
33: * @method Mage_Api2_Block_Adminhtml_Roles_Buttons setRole(Mage_Api2_Model_Acl_Global_Role $role)
34: * @method Mage_Api2_Model_Acl_Global_Role getRole()
35: */
36: class Mage_Api2_Block_Adminhtml_Roles_Buttons extends Mage_Adminhtml_Block_Template
37: {
38: /**
39: * Construct
40: */
41: public function __construct()
42: {
43: parent::__construct();
44: $this->setTemplate('api2/role/buttons.phtml');
45: }
46:
47: /**
48: * Preparing global layout
49: *
50: * @return Mage_Api2_Block_Adminhtml_Roles_Buttons
51: */
52: protected function _prepareLayout()
53: {
54: $buttons = array(
55: 'backButton' => array(
56: 'label' => Mage::helper('adminhtml')->__('Back'),
57: 'onclick' => sprintf("window.location.href='%s';", $this->getUrl('*/*/')),
58: 'class' => 'back'
59: ),
60: 'resetButton' => array(
61: 'label' => Mage::helper('adminhtml')->__('Reset'),
62: 'onclick' => 'window.location.reload()'
63: ),
64: 'saveButton' => array(
65: 'label' => Mage::helper('adminhtml')->__('Save Role'),
66: 'onclick' => 'roleForm.submit(); return false;',
67: 'class' => 'save'
68: ),
69: 'deleteButton' => array(
70: 'label' => Mage::helper('adminhtml')->__('Delete Role'),
71: 'onclick' => '', //roleId is not set at this moment, so we set script later
72: 'class' => 'delete'
73: ),
74: );
75:
76: foreach ($buttons as $name=>$data) {
77: $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData($data);
78: $this->setChild($name, $button);
79: }
80:
81: return parent::_prepareLayout();
82: }
83:
84: /**
85: * Get back button HTML
86: *
87: * @return string
88: */
89: public function getBackButtonHtml()
90: {
91: return $this->getChildHtml('backButton');
92: }
93:
94: /**
95: * Get reset button HTML
96: *
97: * @return string
98: */
99: public function getResetButtonHtml()
100: {
101: return $this->getChildHtml('resetButton');
102: }
103:
104: /**
105: * Get save button HTML
106: *
107: * @return string
108: */
109: public function getSaveButtonHtml()
110: {
111: return $this->getChildHtml('saveButton');
112: }
113:
114: /**
115: * Get delete button HTML
116: *
117: * @return string
118: */
119: public function getDeleteButtonHtml()
120: {
121: if(!$this->getRole() || !$this->getRole()->getId()
122: || Mage_Api2_Model_Acl_Global_Role::isSystemRole($this->getRole())) {
123:
124: return '';
125: }
126:
127: $this->getChild('deleteButton')->setData('onclick', sprintf("deleteConfirm('%s', '%s')",
128: Mage::helper('adminhtml')->__('Are you sure you want to do this?'),
129: $this->getUrl('*/*/delete', array('id' => $this->getRole()->getId()))
130: ));
131:
132: return $this->getChildHtml('deleteButton');
133: }
134:
135: /**
136: * Get block caption
137: *
138: * @return string
139: */
140: public function getCaption()
141: {
142: return $this->getRole() && $this->getRole()->getId()
143: ? ($this->__('Edit Role') . " '{$this->escapeHtml($this->getRole()->getRoleName())}'")
144: : $this->__('Add New Role');
145: }
146: }
147: