From 1f3f7dcc54711e213a670e47b7acf4d172d10484 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 31 Mar 2014 00:04:34 -0400 Subject: [PATCH] Begin work on the admin field editing screen. --- admin/fields.php | 31 ++++++++++++++-- admin/templates/admin_fields_edit.tpl | 52 +++++++++++++++++++++++++++ admin/templates/admin_fields_list.tpl | 17 +++++++++ admin/templates/admin_header.tpl | 1 + admin/templates/css/admin.css | 4 +++ docs/schema_changes.sql | 13 +++++++ static/admin.js | 16 ++++++++- 7 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 admin/templates/admin_fields_edit.tpl diff --git a/admin/fields.php b/admin/fields.php index 39361bc..a23a626 100644 --- a/admin/fields.php +++ b/admin/fields.php @@ -25,15 +25,42 @@ use \bugdar; use \hoplite\http; require_once HOPLITE_ROOT . '/http/action_controller.php'; +require_once BUGDAR_ROOT . '/includes/model_field.php'; -class FieldsAction extends http\ActionController +class FieldsAction extends http\ActionController implements TemplatePreCaching { + public function TemplateSet() + { + return array('admin_fields_list', 'admin_fields_edit'); + } + public function ActionList(http\Request $request, http\Response $response) { - $response->data['fields'] = array(); + $response->data['fields'] = bugdar\Field::FetchGroup(); $response->context['template'] = 'admin_fields_list'; } + public function ActionNew(http\Request $request, http\Response $response) + { + $response->data['is_new'] = TRUE; + $response->context['template'] = 'admin_fields_edit'; + } + + public function ActionEdit(http\Request $request, http\Response $response) + { + $field = new bugdar\Field(bugdar::$input->InputClean('g', 'field', http\Input::TYPE_STR)); + $response->data['field'] = $field->Fetch(); + $response->context['template'] = 'admin_fields_edit'; + } + + public function ActionSave(http\Request $request, http\Response $response) + { + if ($request->http_method != 'POST') + $this->controller()->StopWithCode(http\ResponseCode::METHOD_NOT_ALLOWED); + + $this->controller()->StopWithRedirect($this->controller()->MakeURL('/fields/list')); + } + protected function _GetActionMethod(http\Request $request) { $method = parent::_GetActionMethod($request); diff --git a/admin/templates/admin_fields_edit.tpl b/admin/templates/admin_fields_edit.tpl new file mode 100644 index 0000000..ff3e1aa --- /dev/null +++ b/admin/templates/admin_fields_edit.tpl @@ -0,0 +1,52 @@ +{%#import 'admin_header'%} + +
+
+ +

{%= ($is_new) ? T('Add New Field') : sprintf(T('Edit Field: %1$s'), $field->title) %}

+ +
+ + + + + + + + + + + + + + + +
+ +
+
+ +{%#import 'admin_footer'%} diff --git a/admin/templates/admin_fields_list.tpl b/admin/templates/admin_fields_list.tpl index a135b46..a53fe4d 100644 --- a/admin/templates/admin_fields_list.tpl +++ b/admin/templates/admin_fields_list.tpl @@ -1,3 +1,20 @@ {%#import 'admin_header'%} + + + + + + {% foreach ($fields as $field): %} + + + + + {% endforeach %} +
NameType
+ {%= $field->title %} +
+ {%= $field->description %} +
{%= $field->type %}
+ {%#import 'admin_footer'%} diff --git a/admin/templates/admin_header.tpl b/admin/templates/admin_header.tpl index d159b02..cb2e336 100644 --- a/admin/templates/admin_header.tpl +++ b/admin/templates/admin_header.tpl @@ -16,3 +16,4 @@
  • {%=T('Fields')%}
  • +
    diff --git a/admin/templates/css/admin.css b/admin/templates/css/admin.css index 9ffad66..7a336b6 100644 --- a/admin/templates/css/admin.css +++ b/admin/templates/css/admin.css @@ -4,6 +4,10 @@ body, input, textarea { font-size: 12pt; } +label { + display: block; +} + #header { background-color: lightgray; margin-bottom: 10px; diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 9de1d44..f4d844b 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -1,2 +1,15 @@ ## SVN $Id$ +CREATE TABLE field +( + title varchar(255) NOT NULL, + description varchar(255) NOT NULL, + type varchar(16) NOT NULL, + validator_pattern varchar(255) NOT NULL, + required bool NOT NULL, + default_value varchar(255) NOT NULL, + can_search bool NOT NULL, + color_foreground varchar(6) NOT NULL, + color_background varchar(6) NOT NULL, + PRIMARY KEY (title) +); diff --git a/static/admin.js b/static/admin.js index 2c9484a..2029413 100644 --- a/static/admin.js +++ b/static/admin.js @@ -12,4 +12,18 @@ angular.module('bugdar.admin.settings', []) value: '@' } }; - }]); \ No newline at end of file + }]); + +angular.module('bugdar.admin.fields', []) + .directive('fieldType', ['$templateCache', function($templateCache) { + return { + restrict: 'A', + replace: true, + template: $templateCache.get('-/admin/fields/field-type-option.tpl'), + scope: { + fieldType: '@' + } + }; + }]) + .controller('FieldEditor', ['$scope', function($scope) { + }]); -- 2.22.5