123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * Admin tax rate save toolbar
- *
- * @author Magento Core Team <core@magentocommerce.com>
- */
- namespace Magento\Tax\Block\Adminhtml\Rate\Toolbar;
- /**
- * Rate toolbar block
- */
- class Save extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\ContainerInterface
- {
- /**
- * @var string
- */
- protected $_template = 'Magento_Tax::toolbar/rate/save.phtml';
- /**
- * @var \Magento\Backend\Block\Widget\Button\ButtonList
- */
- protected $buttonList;
- /**
- * @var \Magento\Backend\Block\Widget\Button\ToolbarInterface
- */
- protected $toolbar;
- /**
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\Backend\Block\Widget\Button\ButtonList $buttonList
- * @param \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Template\Context $context,
- \Magento\Backend\Block\Widget\Button\ButtonList $buttonList,
- \Magento\Backend\Block\Widget\Button\ToolbarInterface $toolbar,
- array $data = []
- ) {
- $this->buttonList = $buttonList;
- $this->toolbar = $toolbar;
- parent::__construct($context, $data);
- }
- /**
- * Init model
- *
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->assign('createUrl', $this->getUrl('tax/rate/save'));
- }
- /**
- * Public wrapper for the button list
- *
- * @param string $buttonId
- * @param array $data
- * @param integer $level
- * @param integer $sortOrder
- * @param string|null $region That button should be displayed in ('toolbar', 'header', 'footer', null)
- * @return $this
- */
- public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
- {
- $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
- return $this;
- }
- /**
- * Public wrapper for the button list
- *
- * @param string $buttonId
- * @return $this
- */
- public function removeButton($buttonId)
- {
- $this->buttonList->remove($buttonId);
- return $this;
- }
- /**
- * Public wrapper for protected _updateButton method
- *
- * @param string $buttonId
- * @param string|null $key
- * @param string $data
- * @return $this
- */
- public function updateButton($buttonId, $key, $data)
- {
- $this->buttonList->update($buttonId, $key, $data);
- return $this;
- }
- /**
- * Prepare layout
- *
- * @return $this
- */
- protected function _prepareLayout()
- {
- $this->buttonList->add(
- 'back',
- [
- 'label' => __('Back'),
- 'onclick' => 'window.location.href=\'' . $this->getUrl('tax/*/') . '\'',
- 'class' => 'back'
- ]
- );
- $this->buttonList->add(
- 'reset',
- ['label' => __('Reset'), 'onclick' => 'window.location.reload()', 'class' => 'reset']
- );
- $rate = (int)$this->getRequest()->getParam('rate');
- if ($rate) {
- $this->buttonList->add(
- 'delete',
- [
- 'label' => __('Delete Rate'),
- 'onclick' => 'deleteConfirm(\'' . __(
- 'Are you sure you want to do this?'
- ) . '\', \'' . $this->getUrl(
- 'tax/*/delete',
- ['rate' => $rate]
- ) . '\')',
- 'class' => 'delete'
- ]
- );
- }
- $this->buttonList->add(
- 'save',
- [
- 'label' => __('Save Rate'),
- 'class' => 'save primary save-rate',
- 'data_attribute' => [
- 'mage-init' => ['button' => ['event' => 'save', 'target' => '#rate-form']],
- ]
- ]
- );
- $this->toolbar->pushButtons($this, $this->buttonList);
- return parent::_prepareLayout();
- }
- /**
- * Check whether button rendering is allowed in current context
- *
- * @param \Magento\Backend\Block\Widget\Button\Item $item
- * @return bool
- */
- public function canRender(\Magento\Backend\Block\Widget\Button\Item $item)
- {
- return !$item->isDeleted();
- }
- }
|