Add channel create
This commit is contained in:
parent
bff62615fa
commit
4ae2bd5b44
6 changed files with 82 additions and 3 deletions
|
@ -59,6 +59,7 @@ class ACL extends \Zend\Permissions\Acl\Acl
|
|||
'/clients/send/{sid}/{cldbid}',
|
||||
|
||||
'/channels/{sid}',
|
||||
'/channels/create/{sid}',
|
||||
'/channels/{sid}/{cid}',
|
||||
'/channels/edit/{sid}/{cid}',
|
||||
'/channels/delete/{sid}/{cid}',
|
||||
|
|
|
@ -270,6 +270,11 @@ $container[ChannelInfoAction::class] = function ($container) {
|
|||
};
|
||||
$app->get('/channels/{sid}/{cid}', ChannelInfoAction::class);
|
||||
|
||||
$container[ChannelCreateAction::class] = function ($container) {
|
||||
return new ChannelCreateAction($container);
|
||||
};
|
||||
$app->post('/channels/create/{sid}', ChannelCreateAction::class);
|
||||
|
||||
$container[ChannelEditAction::class] = function ($container) {
|
||||
return new ChannelEditAction($container);
|
||||
};
|
||||
|
|
|
@ -134,6 +134,15 @@ server_info.send.message: "Message"
|
|||
|
||||
# channels
|
||||
channels.delete: "Delete"
|
||||
channels.h.actions: "Actions"
|
||||
channels.h.details: "Details"
|
||||
channels.create: "Create a channel"
|
||||
channels.create.channel_name: "Name"
|
||||
channels.create.channel_order: "Order"
|
||||
channels.create.semi_permanent: "Semi permanent"
|
||||
channels.create.permanent: "Permanent"
|
||||
channels.create.inherit: "Has a parent?"
|
||||
channels.create.parent: "Parent"
|
||||
|
||||
# channel info
|
||||
channel_info.h.files: "Files"
|
||||
|
|
30
src/Control/Actions/ChannelCreateAction.php
Normal file
30
src/Control/Actions/ChannelCreateAction.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
|
||||
final class ChannelCreateAction extends AbstractAction
|
||||
{
|
||||
public function __invoke(Request $request, Response $response, $args)
|
||||
{
|
||||
$sid = $args['sid'];
|
||||
|
||||
$body = $request->getParsedBody();
|
||||
$inherit = $body['inherit'];
|
||||
|
||||
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
|
||||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
|
||||
if (!$inherit) {
|
||||
unset($body['cpid']);
|
||||
}
|
||||
|
||||
unset($body['inherit']);
|
||||
|
||||
$channelCreateResult = $this->ts->getInstance()->channelCreate($body);
|
||||
|
||||
$this->flash->addMessage('success', $this->translator->trans('done'));
|
||||
|
||||
return $response->withRedirect('/channels/' . $sid);
|
||||
}
|
||||
}
|
|
@ -13,11 +13,23 @@ final class ChannelsAction extends AbstractAction
|
|||
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
|
||||
|
||||
$dataResult = $this->ts->getInstance()->channelList();
|
||||
$channels = $this->ts->getInstance()->getElement('data', $dataResult);
|
||||
$channelParents = [];
|
||||
|
||||
$channelOrders = [];
|
||||
$channelOrders['---'] = 0;
|
||||
|
||||
foreach ($channels as $channel) {
|
||||
$channelParents[$channel['channel_name']] = $channel['cid'];
|
||||
$channelOrders[$channel['channel_name']] = $channel['cid'];
|
||||
}
|
||||
|
||||
// render GET
|
||||
$this->view->render($response, 'channels.twig', [
|
||||
'title' => $this->translator->trans('channels.title'),
|
||||
'data' => $this->ts->getInstance()->getElement('data', $dataResult),
|
||||
'channels' => $channels,
|
||||
'channelParents' => $channelParents,
|
||||
'channelOrders' => $channelOrders,
|
||||
'sid' => $sid
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,30 @@
|
|||
|
||||
{% block content %}
|
||||
<h1 class="header">{{ title }}</h1>
|
||||
{% if data|length > 0 %}
|
||||
{% include 'table.twig' with {'data': data,
|
||||
|
||||
<h2 class="header">{% trans %}channels.h.actions{% endtrans %}</h2>
|
||||
{% include 'form.twig' with {
|
||||
'fields': [
|
||||
{
|
||||
'header_label': 'channels.create'|trans,
|
||||
'label': '<i class="material-icons">check_circle</i>',
|
||||
'uri': '/channels/create/' ~ sid,
|
||||
'uri_method': 'post',
|
||||
'fields': [
|
||||
{'type': 'text', 'key': 'channel_name', 'label': 'channels.create.channel_name'|trans},
|
||||
{'type': 'select', 'key': 'channel_order', 'options': channelOrders, 'label': 'channels.create.channel_order'|trans},
|
||||
{'type': 'checkbox', 'key': 'channel_flag_semi_permanent', 'label': 'channels.create.semi_permanent'|trans},
|
||||
{'type': 'checkbox', 'key': 'channel_flag_permanent', 'label': 'channels.create.permanent'|trans},
|
||||
{'type': 'checkbox', 'key': 'inherit', 'label': 'channels.create.inherit'|trans},
|
||||
{'type': 'select', 'key': 'cpid', 'options': channelParents, 'label': 'channels.create.parent'|trans},
|
||||
]
|
||||
},
|
||||
]
|
||||
} %}
|
||||
|
||||
{% if channels|length > 0 %}
|
||||
<h2 class="header">{% trans %}channels.h.details{% endtrans %}</h2>
|
||||
{% include 'table.twig' with {'data': channels,
|
||||
'links': [{'key': 'cid', 'uri': '/channels/' ~ sid}],
|
||||
'additional_links': [
|
||||
{
|
||||
|
|
Reference in a new issue