mirror of https://github.com/MISP/MISP
Merge pull request #7633 from righel/migrate-news-views
chg: migrate news views to factory.pull/7842/head
commit
d0633c2f62
|
@ -1,16 +1,16 @@
|
|||
<?php
|
||||
App::uses('AppController', 'Controller');
|
||||
App::uses('AppController', 'Controller', 'CRUD');
|
||||
|
||||
class NewsController extends AppController
|
||||
{
|
||||
public $components = array('Session', 'RequestHandler');
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 5,
|
||||
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user van view/page.
|
||||
'order' => array(
|
||||
'News.id' => 'DESC'
|
||||
),
|
||||
'limit' => 5,
|
||||
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user van view/page.
|
||||
'order' => array(
|
||||
'News.id' => 'DESC'
|
||||
),
|
||||
);
|
||||
|
||||
public function index()
|
||||
|
@ -69,22 +69,15 @@ class NewsController extends AppController
|
|||
$this->request->data = $this->News->read(null, $id);
|
||||
$this->set('newsItem', $this->request->data);
|
||||
}
|
||||
$this->render('add');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
if (!$this->request->is('post')) {
|
||||
throw new MethodNotAllowedException();
|
||||
$this->defaultModel = 'News';
|
||||
$this->CRUD->delete($id);
|
||||
if ($this->IndexFilter->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->News->id = $id;
|
||||
if (!$this->News->exists()) {
|
||||
throw new NotFoundException('Invalid news item');
|
||||
}
|
||||
if ($this->News->delete()) {
|
||||
$this->Flash->success(__('News item deleted.'));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
}
|
||||
$this->Flash->error(__('News item could not be deleted.'));
|
||||
$this->redirect(array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +1,42 @@
|
|||
<div class="news form">
|
||||
<?php
|
||||
echo $this->Form->create('News');
|
||||
?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('Add News Item'); ?></legend>
|
||||
<?php
|
||||
echo $this->Form->input('title', array(
|
||||
'type' => 'text',
|
||||
'error' => array('escape' => false),
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge'
|
||||
));
|
||||
?>
|
||||
<div class="input clear"></div>
|
||||
<?php
|
||||
echo $this->Form->input('message', array(
|
||||
'type' => 'textarea',
|
||||
'error' => array('escape' => false),
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge'
|
||||
));
|
||||
?>
|
||||
<div class="input clear"></div>
|
||||
<?php
|
||||
echo $this->Form->input('anonymise', array(
|
||||
'checked' => false,
|
||||
'label' => __('Create anonymously'),
|
||||
));
|
||||
?>
|
||||
</fieldset>
|
||||
<?php
|
||||
echo $this->Form->button(__('Submit'), array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'news', 'menuItem' => 'add'));
|
||||
?>
|
||||
$edit = $this->request->params['action'] === 'edit' ? true : false;
|
||||
echo $this->element(
|
||||
'/genericElements/SideMenu/side_menu',
|
||||
[
|
||||
'menuList' => 'news',
|
||||
'menuItem' => $edit ? 'edit' : 'add'
|
||||
]
|
||||
);
|
||||
|
||||
echo $this->element('genericElements/Form/genericForm', [
|
||||
'data' => [
|
||||
'title' => $edit ? __('Edit News Item') : __('Add News Item'),
|
||||
'fields' => [
|
||||
[
|
||||
'field' => 'title',
|
||||
'label' => __('Title'),
|
||||
'type' => 'text',
|
||||
'error' => ['escape' => false],
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge',
|
||||
],
|
||||
[
|
||||
'field' => 'message',
|
||||
'label' => __('Message'),
|
||||
'type' => 'textarea',
|
||||
'error' => ['escape' => false],
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge'
|
||||
],
|
||||
[
|
||||
'field' => 'anonymise',
|
||||
'label' => __('Create anonymously'),
|
||||
'type' => 'checkbox',
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'action' => $this->request->params['action'],
|
||||
'ajaxSubmit' => 'submitGenericFormInPlace();'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<div class="news form">
|
||||
<?php
|
||||
echo $this->Form->create('News');
|
||||
?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('Edit News Item'); ?></legend>
|
||||
<?php
|
||||
echo $this->Form->input('title', array(
|
||||
'type' => 'text',
|
||||
'error' => array('escape' => false),
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge'
|
||||
));
|
||||
?>
|
||||
<div class="input clear"></div>
|
||||
<?php
|
||||
echo $this->Form->input('message', array(
|
||||
'type' => 'textarea',
|
||||
'error' => array('escape' => false),
|
||||
'div' => 'input clear',
|
||||
'class' => 'input-xxlarge'
|
||||
));
|
||||
?>
|
||||
<div class="input clear"></div>
|
||||
<?php
|
||||
echo $this->Form->input('anonymise', array(
|
||||
'type' => 'checkbox',
|
||||
'checked' => $newsItem['News']['user_id'] == 0,
|
||||
'label' => __('Create anonymously'),
|
||||
));
|
||||
?>
|
||||
</fieldset>
|
||||
<?php
|
||||
echo $this->Form->button(__('Submit'), array('class' => 'btn btn-primary'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'news', 'menuItem' => 'edit'));
|
||||
?>
|
|
@ -1,54 +1,61 @@
|
|||
<div class="templates view">
|
||||
<h2><?php echo __('News');?></h2>
|
||||
<div>
|
||||
<?php
|
||||
if (!empty($newsItems)):
|
||||
foreach ($newsItems as $newsItem): ?>
|
||||
<div class="templateTableRow" style="width:800px;">
|
||||
<div class="templateElementHeader" style="width:100%;position:relative;<?php if ($newsItem['News']['new']) echo 'background-color:red;'?>">
|
||||
<div class="templateGlass"></div>
|
||||
<div class ="templateElementHeaderText" style="width:100%;">
|
||||
<div style="float:left;width:83%;"><?php echo $newsItem['User']['email'] ? h($newsItem['User']['email']) : 'Administrator'; ?></div>
|
||||
<div style="float:left;width:17%;"><?= $this->Time->time($newsItem['News']['date_created']); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="padding:6px;">
|
||||
<h4><?php echo h($newsItem['News']['title']);?></h4>
|
||||
<?php
|
||||
$message = h($newsItem['News']['message']);
|
||||
echo nl2br(preg_replace('#https?:\/\/[^\s]*#i', '<a href="$0">$0</a>', $message));
|
||||
if ($isSiteAdmin):
|
||||
?>
|
||||
<br /><a href="<?php echo $baseurl; ?>/news/edit/<?php echo h($newsItem['News']['id']);?>" class="fa fa-edit" title="<?php echo __('Edit news message');?>" aria-label="<?php echo __('Edit');?>"></a>
|
||||
<?php
|
||||
echo $this->Form->postLink('', array('action' => 'delete', $newsItem['News']['id']), array('class' => 'fa fa-trash', 'title' => __('Delete'), 'aria-label' => __('Delete')), __('Are you sure you want to delete news item #%s?', $newsItem['News']['id']));
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<?php
|
||||
endforeach;
|
||||
echo $this->Paginator->counter(array(
|
||||
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
|
||||
));
|
||||
?>
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
echo $this->Paginator->prev('« ' . __('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') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
else:
|
||||
echo __('There are currently no news messages.');
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'news', 'menuItem' => 'index'));
|
||||
?>
|
||||
|
||||
$this->set('menuData', ['menuList' => 'news', 'menuItem' => 'index']);
|
||||
|
||||
echo $this->element('genericElements/IndexTable/scaffold', [
|
||||
'scaffold_data' => [
|
||||
'data' => [
|
||||
'data' => $newsItems,
|
||||
'fields' => [
|
||||
[
|
||||
'name' => __('Id'),
|
||||
'sort' => 'id',
|
||||
'data_path' => 'News.id'
|
||||
],
|
||||
[
|
||||
'name' => __('User'),
|
||||
'sort' => 'email',
|
||||
'data_path' => 'User.email'
|
||||
],
|
||||
[
|
||||
'name' => __('Title'),
|
||||
'sort' => 'title',
|
||||
'data_path' => 'News.title'
|
||||
],
|
||||
[
|
||||
'name' => __('Message'),
|
||||
'sort' => 'message',
|
||||
'data_path' => 'News.message'
|
||||
],
|
||||
[
|
||||
'name' => __('Created at'),
|
||||
'sort' => 'date_created',
|
||||
'data_path' => 'News.date_created',
|
||||
'element' => 'datetime'
|
||||
],
|
||||
|
||||
],
|
||||
'title' => empty($ajax) ? __('News') : false,
|
||||
'pull' => 'right',
|
||||
'actions' => [
|
||||
[
|
||||
'url' => $baseurl . '/news/edit',
|
||||
'url_params_data_paths' => [
|
||||
'News.id'
|
||||
],
|
||||
'icon' => 'edit',
|
||||
'title' => 'Edit News',
|
||||
],
|
||||
[
|
||||
'onclick' => sprintf(
|
||||
'openGenericModal(\'%s/news/delete/[onclick_params_data_path]\');',
|
||||
$baseurl
|
||||
),
|
||||
'onclick_params_data_path' => 'News.id',
|
||||
'icon' => 'trash',
|
||||
'title' => __('Delete news'),
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
|
Loading…
Reference in New Issue