Skip to content

Commit f44451a

Browse files
authored
Merge pull request #2 from landofcoder/feature/blacklist
Feature/blacklist
2 parents 51ce4a7 + fbd73b7 commit f44451a

File tree

28 files changed

+1690
-67
lines changed

28 files changed

+1690
-67
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © landofcoder.com All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Lof\ChatSystem\Block\Adminhtml\Blacklist\Edit;
9+
10+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
12+
class BackButton extends GenericButton implements ButtonProviderInterface
13+
{
14+
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
return [
21+
'label' => __('Back'),
22+
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
23+
'class' => 'back',
24+
'sort_order' => 10
25+
];
26+
}
27+
28+
/**
29+
* Get URL for back (reset) button
30+
*
31+
* @return string
32+
*/
33+
public function getBackUrl()
34+
{
35+
return $this->getUrl('*/*/');
36+
}
37+
}
38+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © landofcoder.com All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Lof\ChatSystem\Block\Adminhtml\Blacklist\Edit;
9+
10+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
12+
class DeleteButton extends GenericButton implements ButtonProviderInterface
13+
{
14+
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
$data = [];
21+
if ($this->getModelId()) {
22+
$data = [
23+
'label' => __('Delete Blacklist'),
24+
'class' => 'delete',
25+
'on_click' => 'deleteConfirm(\'' . __(
26+
'Are you sure you want to do this?'
27+
) . '\', \'' . $this->getDeleteUrl() . '\')',
28+
'sort_order' => 20,
29+
];
30+
}
31+
return $data;
32+
}
33+
34+
/**
35+
* Get URL for delete button
36+
*
37+
* @return string
38+
*/
39+
public function getDeleteUrl()
40+
{
41+
return $this->getUrl('*/*/delete', ['blacklist_id' => $this->getModelId()]);
42+
}
43+
}
44+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © landofcoder.com All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Lof\ChatSystem\Block\Adminhtml\Blacklist\Edit;
9+
10+
use Magento\Backend\Block\Widget\Context;
11+
12+
abstract class GenericButton
13+
{
14+
15+
protected $context;
16+
17+
/**
18+
* @param \Magento\Backend\Block\Widget\Context $context
19+
*/
20+
public function __construct(Context $context)
21+
{
22+
$this->context = $context;
23+
}
24+
25+
/**
26+
* Return model ID
27+
*
28+
* @return int|null
29+
*/
30+
public function getModelId()
31+
{
32+
return $this->context->getRequest()->getParam('blacklist_id');
33+
}
34+
35+
/**
36+
* Generate url by route and parameters
37+
*
38+
* @param string $route
39+
* @param array $params
40+
* @return string
41+
*/
42+
public function getUrl($route = '', $params = [])
43+
{
44+
return $this->context->getUrlBuilder()->getUrl($route, $params);
45+
}
46+
}
47+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © landofcoder.com All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Lof\ChatSystem\Block\Adminhtml\Blacklist\Edit;
9+
10+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
12+
class SaveAndContinueButton extends GenericButton implements ButtonProviderInterface
13+
{
14+
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
return [
21+
'label' => __('Save and Continue Edit'),
22+
'class' => 'save',
23+
'data_attribute' => [
24+
'mage-init' => [
25+
'button' => ['event' => 'saveAndContinueEdit'],
26+
],
27+
],
28+
'sort_order' => 80,
29+
];
30+
}
31+
}
32+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © landofcoder.com All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Lof\ChatSystem\Block\Adminhtml\Blacklist\Edit;
9+
10+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
11+
12+
class SaveButton extends GenericButton implements ButtonProviderInterface
13+
{
14+
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
return [
21+
'label' => __('Save Blacklist'),
22+
'class' => 'save primary',
23+
'data_attribute' => [
24+
'mage-init' => ['button' => ['event' => 'save']],
25+
'form-role' => 'save',
26+
],
27+
'sort_order' => 90,
28+
];
29+
}
30+
}
31+

Block/Adminhtml/Chat/Edit.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,19 @@ protected function _construct()
5656
$this->_controller = 'adminhtml_chat';
5757

5858
parent::_construct();
59+
$chat_id = $this->_coreRegistry->registry('lofchatsystem_chat')->getId();
5960
$this->buttonList->remove('save');
6061
$this->buttonList->remove('reset');
62+
$this->buttonList->add(
63+
'blacklist',
64+
[
65+
'label' => __('Add to Blacklist'),
66+
'class' => 'save primary',
67+
'onclick' => 'setLocation(\'' . $this->getUrl('lofchatsystem/*/addBlacklist', ["chat_id"=>(int)$chat_id]) . '\')'
68+
]
69+
70+
);
71+
6172
//$this->buttonList->add(
6273
//'close_chat',
6374
//[
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?php
2+
/**
3+
* Venustheme
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Venustheme.com license that is
8+
* available through the world-wide-web at this URL:
9+
* http://www.venustheme.com/license-agreement.html
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Venustheme
17+
* @package Lof_ChatSystem
18+
* @copyright Copyright (c) 2018 Venustheme (http://www.venustheme.com/)
19+
* @license http://www.venustheme.com/LICENSE-1.0.html
20+
*/
21+
namespace Lof\ChatSystem\Block\Adminhtml\Chat\Edit\Tab;
22+
23+
24+
use Magento\Framework\UrlInterface;
25+
/**
26+
* @SuppressWarnings(PHPMD.DepthOfInheritance)
27+
*/
28+
class Blacklist extends \Magento\Backend\Block\Widget\Form\Generic implements
29+
\Magento\Backend\Block\Widget\Tab\TabInterface
30+
{
31+
32+
/**
33+
* @var UrlInterface
34+
*/
35+
protected $urlBuilder;
36+
37+
protected $order;
38+
39+
protected $orderRepository;
40+
/**
41+
* @param \Magento\Backend\Block\Template\Context $context
42+
* @param \Magento\Framework\Registry $registry
43+
* @param \Magento\Framework\Data\FormFactory $formFactory
44+
* @param \Magento\Theme\Model\Layout\Source\Layout $pageLayout
45+
* @param \Magento\Framework\View\Customer Information\Theme\LabelFactory $labelFactory
46+
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
47+
* @param array $data
48+
*/
49+
public function __construct(
50+
\Magento\Backend\Block\Template\Context $context,
51+
\Magento\Framework\Registry $registry,
52+
UrlInterface $urlBuilder,
53+
\Magento\Sales\Model\Order $order,
54+
\Magento\Framework\Data\FormFactory $formFactory,
55+
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
56+
array $data = []
57+
) {
58+
$this->orderRepository = $orderRepository;
59+
$this->order = $order;
60+
$this->urlBuilder = $urlBuilder;
61+
parent::__construct($context, $registry, $formFactory, $data);
62+
}
63+
64+
/**
65+
* Prepare form tab configuration
66+
*
67+
* @return void
68+
*/
69+
protected function _construct()
70+
{
71+
parent::_construct();
72+
$this->setShowGlobalIcon(true);
73+
}
74+
75+
/**
76+
* Initialise form fields
77+
*
78+
* @return $this
79+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
80+
*/
81+
protected function _prepareForm()
82+
{
83+
/*
84+
* Checking if user have permissions to save information
85+
*/
86+
$isElementDisabled = !$this->_isAllowedAction('Lof_ChatSystem::chat_edit');
87+
/** @var \Magento\Framework\Data\Form $form */
88+
$form = $this->_formFactory->create(['data' => ['html_id_prefix' => 'chat_']]);
89+
90+
$model = $this->_coreRegistry->registry('lofchatsystem_chat');
91+
92+
$fieldset = $form->addFieldset(
93+
'base_fieldset',
94+
['legend' => __('Blacklist'), 'class' => 'fieldset-wide', 'disabled' => $isElementDisabled]
95+
);
96+
$fieldset->addField(
97+
'customer_id',
98+
'text',
99+
[
100+
'name' => 'customer_id',
101+
'label' => __('Customer Id'),
102+
'required' => false,
103+
'title' => __('Customer Id')
104+
]
105+
);
106+
$fieldset->addField(
107+
'ip',
108+
'text',
109+
[
110+
'name' => 'ip',
111+
'label' => __('IP address'),
112+
'title' => __('IP address'),
113+
'required' => false,
114+
'class' => 'ip'
115+
]
116+
);
117+
$fieldset->addField(
118+
'customer_email',
119+
'text',
120+
[
121+
'name' => 'customer_email',
122+
'label' => __('Customer Email'),
123+
'title' => __('Customer Email')
124+
]
125+
);
126+
$form->setValues($model->getData());
127+
128+
$this->setForm($form);
129+
130+
return parent::_prepareForm();
131+
}
132+
133+
/**
134+
* Prepare label for tab
135+
*
136+
* @return \Magento\Framework\Phrase
137+
*/
138+
public function getTabLabel()
139+
{
140+
return __('Blacklist Information');
141+
}
142+
143+
/**
144+
* Prepare title for tab
145+
*
146+
* @return \Magento\Framework\Phrase
147+
*/
148+
public function getTabTitle()
149+
{
150+
return __('Blacklist Information');
151+
}
152+
153+
/**
154+
* {@inheritdoc}
155+
*/
156+
public function canShowTab()
157+
{
158+
return true;
159+
}
160+
161+
/**
162+
* {@inheritdoc}
163+
*/
164+
public function isHidden()
165+
{
166+
return false;
167+
}
168+
169+
/**
170+
* Check permission for passed action
171+
*
172+
* @param string $resourceId
173+
* @return bool
174+
*/
175+
protected function _isAllowedAction($resourceId)
176+
{
177+
return $this->_authorization->isAllowed($resourceId);
178+
}
179+
}

0 commit comments

Comments
 (0)