Merge branch 'template_refactor' into develop

pull/7600/head
iglocska 2021-07-23 11:30:11 +02:00
commit 26f9974865
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
8 changed files with 237 additions and 273 deletions

View File

@ -6,7 +6,7 @@ App::uses('File', 'Utility');
class TemplatesController extends AppController
{
public $components = array('Security' ,'RequestHandler');
public $components = array('Security' ,'RequestHandler', 'CRUD');
public $paginate = array(
'limit' => 50,
@ -106,6 +106,7 @@ class TemplatesController extends AppController
$this->set('template', $template);
$this->set('tags', $tagArray);
$this->set('tagInfo', $tags);
$this->render('add');
}
public function view($id)
@ -231,23 +232,20 @@ class TemplatesController extends AppController
public function delete($id)
{
$template = $this->Template->checkAuthorisation($id, $this->Auth->user(), true);
if (!$this->request->is('post')) {
throw new MethodNotAllowedException('This action can only be invoked via a post request.');
}
if (!$this->_isSiteAdmin() && !$template) {
throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to edit it.');
}
if ($this->Template->delete($id, true)) {
$this->Flash->success('Template deleted.');
$this->redirect(array('action' => 'index'));
} else {
$this->Flash->error('The template could not be deleted.');
$this->redirect(array('action' => 'index'));
$this->CRUD->delete($id, [
'validate' => function () use ($id) {
$template = $this->Template->checkAuthorisation($id, $this->Auth->user(), true);
if (!$this->_isSiteAdmin() && !$template) {
throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to edit it.');
}
}
]);
if ($this->IndexFilter->isRest()) {
return $this->restResponsePayload;
}
}
public function templateChoices($id)
{
$this->loadModel('Event');

View File

@ -0,0 +1,52 @@
<div id="tagList">
<label><?php echo __('Tags'); ?></label>
<table>
<tr>
<td>
<table>
<tr id="tags"></tr>
</table>
</td>
<td id="addTagButtonTD">
<button type="button" onClick="activateTagField()" id="addTagButton" title="<?php echo __('Add tag'); ?>" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;">+</button>
</td>
<td id="addTagFieldTD">
<?php
echo ($this->Form->input($fieldData['field'], array('id' => 'hiddenTags', 'div' => 'clear', 'label' => false, 'type' => 'text', 'value' => '[]', 'style' => 'display:none;')));
echo $this->Form->input('tagsPusher', array(
'div' => 'clear',
'id' => 'addTagField',
'options' => array($fieldData['tags']),
'label' => false,
'onChange' => 'tagFieldChange()',
'style' => "height:22px;padding:0px;margin-bottom:0px;display:none;",
'empty' => __('Add a tag'),
));
?>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
var selectedTags = [
<?php
foreach ($fieldData['selectedTags'] as $k => $t) {
if ($k != 0) echo ', ';
echo '"' . h($t['Tag']['id']) . '"';
}
?>
];
var allTags = [
<?php
foreach ($fieldData['tagInfo'] as $tag) {
echo "{'id' : '" . h($tag['Tags']['id']) . "', 'name' : '" . h($tag['Tags']['name']) . "', 'colour' : '" . h($tag['Tags']['colour']) . "'},";
}
?>
];
$(document).ready(function() {
for (var i = 0, len = selectedTags.length; i < len; i++) {
appendTemplateTag(selectedTags[i], 'yes');
}
});
</script>
<?php echo $this->Js->writeBuffer();

View File

@ -0,0 +1,9 @@
<?php
if (!empty($data['TemplateTag'])) {
foreach ($data['TemplateTag'] as $tag) {
?>
<span class="tagComplete" style="background-color:<?php echo h($tag['Tag']['colour']); ?>;color:<?php echo $this->TextColour->getTextColour($tag['Tag']['colour']); ?>"><?php echo h($tag['Tag']['name']); ?></span>
<?php
}
} else echo '&nbsp';

View File

@ -0,0 +1,7 @@
<div id="templateElements" class="view">
<script type="text/javascript">
$(document).ready(function() {
updateIndex(<?php echo $templateId ?>, 'template');
});
</script>
</div>

View File

@ -1,65 +1,45 @@
<div class="templates form">
<?php
echo $this->Form->create('Template');
?>
<fieldset>
<legend><?php echo __('Create Template'); ?></legend>
<?php
echo ($this->Form->input('name', array('div' => 'clear')));
echo ($this->Form->input('tags', array('id' => 'hiddenTags','div' => 'clear', 'label' => false, 'type' => 'text', 'value' => '[]', 'style' => 'display:none;')));
?>
<div id ="tagList">
<label><?php echo __('Tags');?></label>
<table>
<tr>
<td><table><tr id = "tags"></tr></table></td>
<td id = "addTagButtonTD">
<button type="button" onClick="activateTagField()" id="addTagButton" title="<?php echo __('Add tag');?>" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;">+</button>
</td>
<td id = "addTagFieldTD">
<?php
echo $this->Form->input('tagsPusher', array(
'div' => 'clear',
'id' => 'addTagField',
'options' => array($tags),
'label' => false,
'onChange' => 'tagFieldChange()',
'style' => "height:22px;padding:0px;margin-bottom:0px;display:none;",
'empty' => __('Add a tag'),
));
?>
</td>
</tr>
</table>
</div><br />
<?php
echo $this->Form->input('description', array(
'label' => __('Template Description'),
'div' => 'clear',
'type' => 'textarea',
'class' => 'form-control span6',
'placeholder' => __('A description of the template')
));
echo $this->Form->input('share', array(
'label' => __('Share this template with others'),
'type' => 'checkbox'
));
?>
</fieldset>
<?php echo $this->Form->button(__('Create'), array('class' => 'btn btn-primary'));
echo $this->Form->end();?>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'templates', 'menuItem' => 'add'));
?>
<script type="text/javascript">
var selectedTags = [];
var allTags = [
<?php
foreach ($tagInfo as $tag) {
echo "{'id' : '" . h($tag['Tags']['id']) . "', 'name' : '" . h($tag['Tags']['name']) . "', 'colour' : '" . h($tag['Tags']['colour']) . "'},";
}
?>
];
</script>
<?php echo $this->Js->writeBuffer();
$edit = $this->request->params['action'] === 'edit' ? true : false;
echo $this->element('/genericElements/SideMenu/side_menu', [
'menuList' => 'templates',
'menuItem' => $edit ? 'edit' : 'add'
]);
echo $this->element('genericElements/Form/genericForm', [
'data' => [
'title' => $edit ? __('Edit Template') : __('Create Template'),
'fields' => [
[
'field' => 'name',
'label' => __('Name'),
],
[
'field' => 'tags',
'label' => __('Tags'),
'type' => 'tags',
'tags' => $tags,
'selectedTags' => isset($currentTags) ? $currentTags : [],
'tagInfo' => $tagInfo
],
[
'field' => 'description',
'label' => __('Template Description'),
'type' => 'textarea',
'div' => 'input clear',
'class' => 'span6',
'placeholder' => __('A description of the template')
],
[
'field' => 'share',
'label' => __('Share this template with others'),
'type' => 'checkbox'
],
],
'submit' => [
'action' => $this->request->params['action'],
'ajaxSubmit' => 'submitGenericFormInPlace();'
]
]
]);

View File

@ -1,77 +0,0 @@
<div class="templates form">
<?php
echo $this->Form->create('Template');
?>
<fieldset>
<legend><?php echo __('Edit Template'); ?></legend>
<?php
echo ($this->Form->input('name', array('div' => 'clear')));
echo ($this->Form->input('tags', array('id' => 'hiddenTags','div' => 'clear', 'label' => false, 'type' => 'text', 'value' => '[]', 'style' => 'display:none;')));
?>
<div id ="tagList">
<label><?php echo __('Tags');?></label>
<table>
<tr>
<td><table><tr id = "tags"></tr></table></td>
<td id = "addTagButtonTD">
<span role="button" tabindex="0" aria-label="<?php echo __('Add tag');?>" title="<?php echo __('Add tag');?>" onClick="activateTagField()" id="addTagButton" class="btn btn-inverse noPrint" style="line-height:10px; padding: 4px 4px;">+</span>
</td>
<td id = "addTagFieldTD">
<?php
echo $this->Form->input('tagsPusher', array(
'div' => 'clear',
'id' => 'addTagField',
'options' => array($tags),
'label' => false,
'onChange' => 'tagFieldChange()',
'style' => "height:22px;padding:0px;margin-bottom:0px;display:none;",
'empty' => __('Add a tag'),
));
?>
</td>
</tr>
</table>
</div><br />
<?php
echo $this->Form->input('description', array(
'label' => __('Template Description'),
'div' => 'clear',
'type' => 'textarea',
'class' => 'form-control span6',
'placeholder' => __('A description of the template')
));
echo $this->Form->input('share', array(
'label' => __('Share this template with others'),
'type' => 'checkbox'
));
?>
</fieldset>
<?php echo $this->Form->button(__('Edit'), array('class' => 'btn btn-primary'));
echo $this->Form->end();?>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'templates', 'menuItem' => 'edit', 'id' => $id, 'mayModify' => $mayModify));
?>
<script type="text/javascript">
var selectedTags = [
<?php
foreach ($currentTags as $k => $t) {
if ($k != 0) echo ', ';
echo '"' . $t['Tag']['id'] . '"';
}
?>
];
var allTags = [
<?php
foreach ($tagInfo as $tag) {
echo "{'id' : '" . h($tag['Tags']['id']) . "', 'name' : '" . h($tag['Tags']['name']) . "', 'colour' : '" . h($tag['Tags']['colour']) . "'},";
}
?>
];
$(document).ready( function () {
for (var i = 0, len = selectedTags.length; i < len; i++) {
appendTemplateTag(selectedTags[i], 'yes');
}
});
</script>
<?php echo $this->Js->writeBuffer();

View File

@ -1,63 +1,73 @@
<div class="templates index">
<h2><?php echo __('Templates');?></h2>
<div class="pagination">
<ul>
<?php
echo $this->Paginator->prev('&laquo; ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
echo $this->Paginator->next(__('next') . ' &raquo;', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
?>
</ul>
</div>
<table class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo $this->Paginator->sort('id');?></th>
<th><?php echo $this->Paginator->sort('org');?></th>
<th><?php echo $this->Paginator->sort('share');?></th>
<th><?php echo $this->Paginator->sort('name');?></th>
<th><?php echo $this->Paginator->sort('description');?></th>
<?php if ($isAclTemplate): ?>
<th class="actions"><?php echo __('Actions');?></th>
<?php endif; ?>
</tr><?php
foreach ($list as $item): ?>
<tr>
<td class="short" onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php echo h($item['Template']['id']); ?>&nbsp;</td>
<td class="short" onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'">
<?php
echo $this->OrgImg->getOrgImg(array('name' => $item['Template']['org'], 'size' => 24));
?>
&nbsp;
</td>
<td class="short" onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php if ($item['Template']['share']) echo 'Yes'; else echo 'No'; ?>&nbsp;</td>
<td onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php echo h($item['Template']['name']); ?>&nbsp;</td>
<td onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php echo h($item['Template']['description']); ?>&nbsp;</td>
<?php if ($isAclTemplate): ?>
<td class="short action-links">
<?php echo $this->Html->link('', array('action' => 'edit', $item['Template']['id']), array('class' => 'fa fa-edit', 'title' => 'Edit', 'aria-label' => 'Edit'));?>
<?php echo $this->Form->postLink('', array('action' => 'delete', $item['Template']['id']), array('class' => 'fa fa-trash', 'title' => 'Delete', 'aria-label' => 'Delete'), __('Are you sure you want to delete Template #' . $item['Template']['id'] . '?'));?>
</td>
<?php endif; ?>
</tr><?php
endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?>
</p>
<div class="pagination">
<ul>
<?php
echo $this->Paginator->prev('&laquo; ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
echo $this->Paginator->next(__('next') . ' &raquo;', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
?>
</ul>
</div>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'templates', 'menuItem' => 'index'));
$this->set('menuData', ['menuList' => 'templates', 'menuItem' => 'index']);
foreach ($list as &$item) {
$item['Organisation'] = ['name' => $item['Template']['org']];
}
echo $this->element('genericElements/IndexTable/scaffold', [
'scaffold_data' => [
'data' => [
'title' => empty($ajax) ? __('Templates') : false,
'data' => $list,
'fields' => [
[
'name' => 'Id',
'sort' => 'Template.id',
'data_path' => 'Template.id',
'class' => 'short'
],
[
'name' => 'Org',
'sort' => 'Organisation.name',
'data_path' => 'Organisation',
'element' => 'org',
'class' => 'short'
],
[
'name' => 'Share',
'sort' => 'Template.share',
'data_path' => 'Template.share',
'element' => 'boolean',
'class' => 'short'
],
[
'name' => 'Name',
'sort' => 'Template.org',
'data_path' => 'Template.org',
'class' => 'short'
],
[
'name' => 'Description',
'sort' => 'Template.description',
'data_path' => 'Template.description',
'class' => 'bitwider'
]
],
'actions' => [
[
'url' => $baseurl . '/templates/view',
'url_params_data_paths' => ['Template.id'],
'icon' => 'eye'
],
[
'url' => $baseurl . '/templates/edit',
'url_params_data_paths' => [
'Template.id'
],
'icon' => 'edit',
'title' => 'Edit',
],
[
'onclick' => sprintf(
'openGenericModal(\'%s/templates/delete/[onclick_params_data_path]\');',
$baseurl
),
'onclick_params_data_path' => 'Template.id',
'icon' => 'trash',
]
]
]
]
]);

View File

@ -1,56 +1,41 @@
<div class="templates view">
<h2><?php echo __('Template');?></h2>
<dl>
<dt><?php echo __('Id'); ?></dt>
<dd>
<?php echo h($template['Template']['id']); ?>
&nbsp;
</dd>
<dt><?php echo __('Name'); ?></dt>
<dd>
<?php echo h($template['Template']['name']); ?>
&nbsp;
</dd>
<dt><?php echo __('Description'); ?></dt>
<dd>
<?php echo h($template['Template']['description']); ?>
&nbsp;
</dd>
<dt><?php echo __('Tags'); ?></dt>
<dd>
<table>
<tr id = "tags">
<?php
if (!empty($template['TemplateTag'])) {
foreach ($template['TemplateTag'] as $tag) {
echo $this->element('ajaxTemplateTag', array('tag' => $tag, 'editable' => 'no'));
}
} else echo '&nbsp';
?>
</tr>
</table>
</dd>
<dt><?php echo __('Organisation'); ?></dt>
<dd>
<?php echo h($template['Template']['org']); ?>
&nbsp;
</dd>
<dt><?php echo __('Shareable'); ?></dt>
<dd>
<?php
if ($template['Template']['share']) echo __('Yes');
else echo __('No');
?>
</dd>
</dl>
<div id="templateElements">
</div>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'templates', 'menuItem' => 'view', 'mayModify' => $mayModify));
?>
<script type="text/javascript">
$(document).ready( function () {
updateIndex(<?php echo $template['Template']['id']?>, 'template');
});
</script>
$this->set('menuData', ['menuList' => 'templates', 'menuItem' => 'view', 'mayModify' => $mayModify]);
echo $this->element(
'genericElements/SingleViews/single_view',
[
'title' => 'Template',
'data' => $template,
'fields' => [
[
'key' => __('Id'),
'path' => 'Template.id'
],
[
'key' => __('Name'),
'path' => 'Template.name'
],
[
'key' => __('Description'),
'path' => 'Template.description'
],
[
'key' => __('Tags'),
'path' => 'TemplateTag',
'type' => 'tags'
],
[
'key' => __('Organisation'),
'path' => 'Template.org',
],
[
'key' => __('Shareable'),
'path' => 'Template.share',
'type' => 'boolean'
]
]
]
);
echo $this->element('templateElements/templateElements', ['templateId' => $template['Template']['id']]);