|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @Author: nguyen |
| 5 | + * @Date: 2020-06-09 19:40:03 |
| 6 | + * @Last Modified by: nguyen |
| 7 | + * @Last Modified time: 2020-06-09 19:41:14 |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Magepow\Theme\Block\Adminhtml\Theme; |
| 11 | + |
| 12 | +class Edit extends \Magento\Backend\Block\Widget\Form\Container |
| 13 | +{ |
| 14 | + /** |
| 15 | + * _construct |
| 16 | + * @return void |
| 17 | + */ |
| 18 | + protected function _construct() |
| 19 | + { |
| 20 | + $this->_objectId = 'theme_id'; |
| 21 | + $this->_blockGroup = 'Magepow_Theme'; |
| 22 | + $this->_controller = 'adminhtml_theme'; |
| 23 | + |
| 24 | + parent::_construct(); |
| 25 | + |
| 26 | + $this->buttonList->update('save', 'label', __('Save Theme')); |
| 27 | + $this->buttonList->update('delete', 'label', __('Delete')); |
| 28 | + |
| 29 | + if ($this->getRequest()->getParam('current_theme_id')) { |
| 30 | + $this->buttonList->remove('save'); |
| 31 | + $this->buttonList->remove('delete'); |
| 32 | + |
| 33 | + $this->buttonList->remove('back'); |
| 34 | + $this->buttonList->add( |
| 35 | + 'close_window', |
| 36 | + [ |
| 37 | + 'label' => __('Close Window'), |
| 38 | + 'onclick' => 'window.close();', |
| 39 | + ], |
| 40 | + 10 |
| 41 | + ); |
| 42 | + |
| 43 | + $this->buttonList->add( |
| 44 | + 'save_and_continue', |
| 45 | + [ |
| 46 | + 'label' => __('Save and Continue Edit'), |
| 47 | + 'class' => 'save', |
| 48 | + 'onclick' => 'customsaveAndContinueEdit()', |
| 49 | + ], |
| 50 | + 10 |
| 51 | + ); |
| 52 | + |
| 53 | + $this->buttonList->add( |
| 54 | + 'save_and_close', |
| 55 | + [ |
| 56 | + 'label' => __('Save and Close'), |
| 57 | + 'class' => 'save_and_close', |
| 58 | + 'onclick' => 'saveAndCloseWindow()', |
| 59 | + ], |
| 60 | + 10 |
| 61 | + ); |
| 62 | + |
| 63 | + $this->_formScripts[] = " |
| 64 | + require(['jquery'], function($){ |
| 65 | + $(document).ready(function(){ |
| 66 | + var input = $('<input class=\"custom-button-submit\" type=\"submit\" hidden=\"true\" />'); |
| 67 | + $(edit_form).append(input); |
| 68 | +
|
| 69 | + window.customsaveAndContinueEdit = function (){ |
| 70 | + edit_form.action = '".$this->getSaveAndContinueUrl()."'; |
| 71 | + $('.custom-button-submit').trigger('click'); |
| 72 | +
|
| 73 | + } |
| 74 | +
|
| 75 | + window.saveAndCloseWindow = function (){ |
| 76 | + edit_form.action = '".$this->getSaveAndCloseWindowUrl()."'; |
| 77 | + $('.custom-button-submit').trigger('click'); |
| 78 | + } |
| 79 | + }); |
| 80 | + }); |
| 81 | + "; |
| 82 | + |
| 83 | + if ($themeId = $this->getRequest()->getParam('theme_id')) { |
| 84 | + $this->_formScripts[] = ' |
| 85 | + window.theme_id = '.$themeId.'; |
| 86 | + '; |
| 87 | + } |
| 88 | + } else { |
| 89 | + $this->buttonList->add( |
| 90 | + 'save_and_continue', |
| 91 | + [ |
| 92 | + 'label' => __('Save and Continue Edit'), |
| 93 | + 'class' => 'save', |
| 94 | + 'data_attribute' => [ |
| 95 | + 'mage-init' => [ |
| 96 | + 'button' => ['event' => 'saveAndContinueEdit', 'target' => '#edit_form'], |
| 97 | + ], |
| 98 | + ], |
| 99 | + ], |
| 100 | + 10 |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | + if ($this->getRequest()->getParam('saveandclose')) { |
| 105 | + $this->_formScripts[] = 'window.close();'; |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Retrieve the save and continue edit Url. |
| 111 | + * |
| 112 | + * @return string |
| 113 | + */ |
| 114 | + protected function getSaveAndContinueUrl() |
| 115 | + { |
| 116 | + return $this->getUrl( |
| 117 | + '*/*/save', |
| 118 | + [ |
| 119 | + '_current' => true, |
| 120 | + 'back' => 'edit', |
| 121 | + 'tab' => '{{tab_id}}', |
| 122 | + 'store' => $this->getRequest()->getParam('store'), |
| 123 | + 'theme_id' => $this->getRequest()->getParam('theme_id'), |
| 124 | + 'current_theme_id' => $this->getRequest()->getParam('current_theme_id'), |
| 125 | + ] |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Retrieve the save and continue edit Url. |
| 131 | + * |
| 132 | + * @return string |
| 133 | + */ |
| 134 | + protected function getSaveAndCloseWindowUrl() |
| 135 | + { |
| 136 | + return $this->getUrl( |
| 137 | + '*/*/save', |
| 138 | + [ |
| 139 | + '_current' => true, |
| 140 | + 'back' => 'edit', |
| 141 | + 'tab' => '{{tab_id}}', |
| 142 | + 'store' => $this->getRequest()->getParam('store'), |
| 143 | + 'theme_id' => $this->getRequest()->getParam('theme_id'), |
| 144 | + 'current_theme_id' => $this->getRequest()->getParam('current_theme_id'), |
| 145 | + 'saveandclose' => 1, |
| 146 | + ] |
| 147 | + ); |
| 148 | + } |
| 149 | +} |
0 commit comments