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_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
35: {
36: 37: 38: 39: 40:
41: public function __construct()
42: {
43: $this->_objectId = 'page_id';
44: $this->_controller = 'cms_page';
45:
46: parent::__construct();
47:
48: if ($this->_isAllowedAction('save')) {
49: $this->_updateButton('save', 'label', Mage::helper('cms')->__('Save Page'));
50: $this->_addButton('saveandcontinue', array(
51: 'label' => Mage::helper('adminhtml')->__('Save and Continue Edit'),
52: 'onclick' => 'saveAndContinueEdit(\''.$this->_getSaveAndContinueUrl().'\')',
53: 'class' => 'save',
54: ), -100);
55: } else {
56: $this->_removeButton('save');
57: }
58:
59: if ($this->_isAllowedAction('delete')) {
60: $this->_updateButton('delete', 'label', Mage::helper('cms')->__('Delete Page'));
61: } else {
62: $this->_removeButton('delete');
63: }
64: }
65:
66: 67: 68: 69: 70:
71: public function ()
72: {
73: if (Mage::registry('cms_page')->getId()) {
74: return Mage::helper('cms')->__("Edit Page '%s'", $this->htmlEscape(Mage::registry('cms_page')->getTitle()));
75: }
76: else {
77: return Mage::helper('cms')->__('New Page');
78: }
79: }
80:
81: 82: 83: 84: 85: 86:
87: protected function _isAllowedAction($action)
88: {
89: return Mage::getSingleton('admin/session')->isAllowed('cms/page/' . $action);
90: }
91:
92: 93: 94: 95: 96: 97:
98: protected function _getSaveAndContinueUrl()
99: {
100: return $this->getUrl('*/*/save', array(
101: '_current' => true,
102: 'back' => 'edit',
103: 'active_tab' => '{{tab_id}}'
104: ));
105: }
106:
107: 108: 109: 110: 111:
112: protected function _prepareLayout()
113: {
114: $tabsBlock = $this->getLayout()->getBlock('cms_page_edit_tabs');
115: if ($tabsBlock) {
116: $tabsBlockJsObject = $tabsBlock->getJsObjectName();
117: $tabsBlockPrefix = $tabsBlock->getId() . '_';
118: } else {
119: $tabsBlockJsObject = 'page_tabsJsTabs';
120: $tabsBlockPrefix = 'page_tabs_';
121: }
122:
123: $this->_formScripts[] = "
124: function toggleEditor() {
125: if (tinyMCE.getInstanceById('page_content') == null) {
126: tinyMCE.execCommand('mceAddControl', false, 'page_content');
127: } else {
128: tinyMCE.execCommand('mceRemoveControl', false, 'page_content');
129: }
130: }
131:
132: function saveAndContinueEdit(urlTemplate) {
133: var tabsIdValue = " . $tabsBlockJsObject . ".activeTab.id;
134: var tabsBlockPrefix = '" . $tabsBlockPrefix . "';
135: if (tabsIdValue.startsWith(tabsBlockPrefix)) {
136: tabsIdValue = tabsIdValue.substr(tabsBlockPrefix.length)
137: }
138: var template = new Template(urlTemplate, /(^|.|\\r|\\n)({{(\w+)}})/);
139: var url = template.evaluate({tab_id:tabsIdValue});
140: editForm.submit(url);
141: }
142: ";
143: return parent::_prepareLayout();
144: }
145: }
146: