new: added noticelist view

pull/3233/head
iglocska 2018-05-07 06:36:56 +02:00
parent 5b1689071d
commit 13e407fd7c
5 changed files with 89 additions and 5 deletions

View File

@ -138,13 +138,11 @@ class NoticelistsController extends AppController {
public function view($id) {
if (!is_numeric($id)) throw new NotFoundException('Invalid ID.');
$noticelist = $this->Noticelist->find('first', array('contain' => array('NoticelistEntry', 'NoticelistType'), 'conditions' => array('id' => $id)));
$noticelist = $this->Noticelist->find('first', array('contain' => array('NoticelistEntry'), 'conditions' => array('id' => $id)));
if (empty($noticelist)) throw new NotFoundException('Noticelist not found.');
if ($this->_isRest()) {
$noticelist['Noticelist']['NoticelistEntry'] = $noticelist['NoticelistEntry'];
$noticelist['Noticelist']['NoticelistType'] = $noticelist['NoticelistType'];
$this->set('Noticelist', $noticelist['Noticelist']);
$this->set('_serialize', array('Noticelist'));
return $this->RestResponse->viewData($noticelist, $this->response->type());
} else {
$this->set('noticelist', $noticelist);
}

View File

@ -273,6 +273,15 @@
endif;
break;
case 'noticelist':?>
<?php if ($menuItem == 'view'): ?><li class="active"><a href="#"><?php echo __('View Noticelist');?></a></li><?php endif;?>
<li id='liindex'><?php echo $this->Html->link(__('List Noticelists'), array('action' => 'index'));?></li>
<?php if ($isSiteAdmin): ?>
<li><?php echo $this->Form->postLink(__('Update Noticelists'), '/noticelists/update'); ?></li>
<?php
endif;
break;
case 'whitelist':?>
<li id='liindex'><?php echo $this->Html->link(__('List Whitelist'), array('admin' => $isSiteAdmin, 'action' => 'index'));?></li>
<?php if ($isSiteAdmin): ?>

View File

@ -57,7 +57,7 @@
echo sprintf('<td class="short" ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), h($item['Noticelist']['version']));
if ($isSiteAdmin) {
$onClick = 'toggleSetting(event, \'noticelist_enable\', \'' . h($item['Noticelist']['id']) . '\'); ';
$input = '<input id="checkbox_' . h($item['Noticelist']['id']) . '" type="checkbox" onClick="' . $onClick . '" ' . ($item['Noticelist']['enabled'] ? 'checked' : '') . ' />';
$input = '<input id="checkBox_' . h($item['Noticelist']['id']) . '" type="checkbox" onClick="' . $onClick . '" ' . ($item['Noticelist']['enabled'] ? 'checked' : '') . ' />';
echo '<td class="short" id="checkbox_row_' . h($item['Noticelist']['id']) . '">' . $input . '</td>';
}
$actions = '';

View File

@ -0,0 +1,71 @@
<div class="noticelist view">
<h2><?php echo h(strtoupper($noticelist['Noticelist']['name'])); ?></h2>
<?php
$field_names = array('id', 'name', 'version', 'expanded_name', 'ref', 'geographical_area', 'enabled');
$fields = array();
foreach ($field_names as $field_name) {
if ($field_name == 'ref' || $field_name == 'geographical_area') {
$value = json_decode($noticelist['Noticelist'][$field_name]);
foreach ($value as $k => $v) {
if ($field_name == 'ref') {
$value[$k] = '<a href="' . h($v) . '">' . h($v) . '</a>';
} else {
$value[$k] = h($v);
}
}
$value = implode(PHP_EOL, $value);
} else if ($field_name == 'enabled') {
$value = $noticelist['Noticelist']['enabled'] ? '<span class="green">Yes</span>&nbsp;&nbsp;' : '<span class="red">No</span>&nbsp;&nbsp;';
if ($isSiteAdmin) {
if ($noticelist['Noticelist']['enabled']) {
$value .= $this->Form->postLink('(disable)', array('action' => 'enableNoticelist', h($noticelist['Noticelist']['id'])), array('title' => 'Disable'));
} else {
$value .= $this->Form->postLink('(enable)', array('action' => 'enableNoticelist', h($noticelist['Noticelist']['id']), 'true') ,array('title' => 'Enable'));
}
}
} else {
$value = h($noticelist['Noticelist'][$field_name]);
}
$fields[] = sprintf('<dt>%s</dt><dd>%s</dd>', __(Inflector::humanize($field_name)), $value);
}
$dl = implode($fields);
echo sprintf('<dl>%s</dl>', $dl);
?>
<br />
<h3><?php echo __('Values');?></h3>
<div>
<table class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo __('Scope'); ?></th>
<th><?php echo __('Field'); ?></th>
<th><?php echo __('Value'); ?></th>
<th><?php echo __('Tags'); ?></th>
<th><?php echo __('Message'); ?></th>
</tr>
<?php
foreach ($noticelist['NoticelistEntry'] as $entry) {
$tr = array();
$array_fields = array('scope', 'field', 'value', 'tags');
foreach ($array_fields as $af) {
$tr []= '<td class="short">' . implode('<br />', h($entry['data'][$af])) . '</td>';
}
$tr []= '<td>' . h($entry['data']['message']['en']) . '</td>';
echo sprintf('<tr>%s</tr>', implode('', $tr));
}
?>
</table>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('input:checkbox').removeAttr('checked');
$('.mass-select').hide();
$('.select_taxonomy, .select_all').click(function(){
taxonomyListAnyCheckBoxesChecked();
});
});
</script>
<?php
echo $this->element('side_menu', array('menuList' => 'noticelist', 'menuItem' => 'view'));
?>

View File

@ -152,6 +152,12 @@ function toggleSetting(e, setting, id) {
replacementForm = '/ObjectTemplates/getToggleField/';
searchString = 'activated';
break;
case 'noticelist_enable':
formID = '#NoticelistIndexForm';
dataDiv = '#NoticelistData';
replacementForm = '/noticelists/getToggleField/';
searchString = 'enabled';
break;
}
$(dataDiv).val(id);
var formData = $(formID).serialize();