Modernise some of the new admin section.
[bugdar.git] / admin / fields.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2002-2014 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 namespace bugdar\admin;
23
24 use \bugdar;
25 use \hoplite\http;
26
27 require_once HOPLITE_ROOT . '/http/action_controller.php';
28 require_once BUGDAR_ROOT . '/includes/model_field.php';
29
30 class FieldsAction extends http\ActionController implements TemplatePreCaching
31 {
32 public function TemplateSet()
33 {
34 return ['admin_fields_list', 'admin_fields_edit'];
35 }
36
37 public function ActionList(http\Request $request, http\Response $response)
38 {
39 $response->data['fields'] = bugdar\Field::FetchGroup();
40 $response->context['template'] = 'admin_fields_list';
41 }
42
43 public function ActionNew(http\Request $request, http\Response $response)
44 {
45 $response->data['is_new'] = TRUE;
46 $response->context['template'] = 'admin_fields_edit';
47 }
48
49 public function ActionEdit(http\Request $request, http\Response $response)
50 {
51 $field = new bugdar\Field(filter_input(INPUT_GET, 'field', FILTER_SANITIZE_STRING));
52 $response->data['field'] = $field->Fetch();
53 $response->context['template'] = 'admin_fields_edit';
54 }
55
56 public function ActionSave(http\Request $request, http\Response $response)
57 {
58 if ($request->http_method != 'POST')
59 $this->controller()->StopWithCode(http\ResponseCode::METHOD_NOT_ALLOWED);
60
61 var_dump($request);
62 //$this->controller()->StopWithRedirect($this->controller()->MakeURL('/fields/list'));
63 }
64
65 protected function _GetActionMethod(http\Request $request)
66 {
67 $method = parent::_GetActionMethod($request);
68 return $method ? $method : 'ActionList';
69 }
70 }