diff --git a/app/Controller/NewsController.php b/app/Controller/NewsController.php index 2601a3edd..e7ce8c257 100755 --- a/app/Controller/NewsController.php +++ b/app/Controller/NewsController.php @@ -1,16 +1,16 @@ 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')); } } diff --git a/app/View/News/add.ctp b/app/View/News/add.ctp index 4d1ea7661..376f5505d 100755 --- a/app/View/News/add.ctp +++ b/app/View/News/add.ctp @@ -1,39 +1,42 @@ -
Form->create('News'); -?> -
- - Form->input('title', array( - 'type' => 'text', - 'error' => array('escape' => false), - 'div' => 'input clear', - 'class' => 'input-xxlarge' - )); - ?> -
- Form->input('message', array( - 'type' => 'textarea', - 'error' => array('escape' => false), - 'div' => 'input clear', - 'class' => 'input-xxlarge' - )); - ?> -
- Form->input('anonymise', array( - 'checked' => false, - 'label' => __('Create anonymously'), - )); - ?> -
- Form->button(__('Submit'), array('class' => 'btn btn-primary')); - echo $this->Form->end(); - ?> -
-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();' + ] + ] +]); diff --git a/app/View/News/edit.ctp b/app/View/News/edit.ctp deleted file mode 100644 index 2f4d0e8b5..000000000 --- a/app/View/News/edit.ctp +++ /dev/null @@ -1,40 +0,0 @@ -
-Form->create('News'); -?> -
- - Form->input('title', array( - 'type' => 'text', - 'error' => array('escape' => false), - 'div' => 'input clear', - 'class' => 'input-xxlarge' - )); - ?> -
- Form->input('message', array( - 'type' => 'textarea', - 'error' => array('escape' => false), - 'div' => 'input clear', - 'class' => 'input-xxlarge' - )); - ?> -
- Form->input('anonymise', array( - 'type' => 'checkbox', - 'checked' => $newsItem['News']['user_id'] == 0, - 'label' => __('Create anonymously'), - )); - ?> -
- Form->button(__('Submit'), array('class' => 'btn btn-primary')); - echo $this->Form->end(); - ?> -
-element('/genericElements/SideMenu/side_menu', array('menuList' => 'news', 'menuItem' => 'edit')); -?> diff --git a/app/View/News/index.ctp b/app/View/News/index.ctp index 6b9c8b698..74ebd33bd 100644 --- a/app/View/News/index.ctp +++ b/app/View/News/index.ctp @@ -1,54 +1,61 @@ -
-

-
- -
-
-
-
-
-
Time->time($newsItem['News']['date_created']); ?>
-
-
-
-

- $0', $message)); - if ($isSiteAdmin): - ?> -
- 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; - ?> -
-
-
- Paginator->counter(array( - 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}') - )); - ?> - - -
-
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'), + ] + ] + ] + ] +]);