From 60cf5dbb71bd3f85a952f724f73c7c409ed426fb Mon Sep 17 00:00:00 2001 From: Tom Price Date: Tue, 9 Aug 2016 18:26:16 +0100 Subject: [PATCH] Convert event forms to be partially embery. --- RIGS/static/js/interaction.js | 56 +- RIGS/templates/RIGS/event_form.html | 667 +++++++++++--------- app/controllers/event/create.js | 4 + app/controllers/event/duplicate.js | 4 + app/mixins/set-time-mixin.js | 23 + app/router.js | 18 +- app/routes/event/create.js | 3 + app/routes/event/edit.js | 3 + app/templates/event/create.hbs | 1 + app/templates/event/duplicate.hbs | 1 + app/templates/event/edit.hbs | 1 + bower.json | 3 +- db.sqlite3 | Bin 577536 -> 579584 bytes ember-cli-build.js | 4 + templates/base_ember.html | 117 ++++ tests/unit/controllers/event/create-test.js | 12 + tests/unit/mixins/set-time-mixin-test.js | 12 + tests/unit/routes/event/create-test.js | 11 + tests/unit/routes/event/duplicate-test.js | 11 + tests/unit/routes/event/edit-test.js | 11 + 20 files changed, 619 insertions(+), 343 deletions(-) create mode 100644 app/controllers/event/create.js create mode 100644 app/controllers/event/duplicate.js create mode 100644 app/mixins/set-time-mixin.js create mode 100644 app/routes/event/create.js create mode 100644 app/routes/event/edit.js create mode 100644 app/templates/event/create.hbs create mode 100644 app/templates/event/duplicate.hbs create mode 100644 app/templates/event/edit.hbs create mode 100644 templates/base_ember.html create mode 100644 tests/unit/controllers/event/create-test.js create mode 100644 tests/unit/mixins/set-time-mixin-test.js create mode 100644 tests/unit/routes/event/create-test.js create mode 100644 tests/unit/routes/event/duplicate-test.js create mode 100644 tests/unit/routes/event/edit-test.js diff --git a/RIGS/static/js/interaction.js b/RIGS/static/js/interaction.js index e7d023e1..9078c91b 100644 --- a/RIGS/static/js/interaction.js +++ b/RIGS/static/js/interaction.js @@ -1,9 +1,30 @@ +// Return a helper with preserved width of cells +var fixHelper = function (e, ui) { + ui.children().each(function () { + $(this).width($(this).width()); + }); + return ui; +}; + function setupItemTable(items_json) { - objectitems = JSON.parse(items_json) + objectitems = JSON.parse(items_json); $.each(objectitems, function (key, val) { objectitems[key] = JSON.parse(val); - }) + }); newitem = -1; + + $("#item-table tbody").sortable({ + helper: fixHelper, + update: function (e, ui) { + info = $(this).sortable("toArray"); + itemorder = []; + $.each(info, function (key, value) { + pk = $('#' + value).data('pk'); + objectitems[pk].fields.order = key; + }); + + } + }); } function nl2br (str, is_xhtml) { @@ -33,7 +54,7 @@ function updatePrices() { } $('#item-table').on('click', '.item-delete', function () { - delete objectitems[$(this).data('pk')] + delete objectitems[$(this).data('pk')]; $('#item-' + $(this).data('pk')).remove(); updatePrices(); }); @@ -73,8 +94,8 @@ $('body').on('submit', '#item-form', function (e) { var fields; if (pk == newitem--) { // Create the new data structure and add it on. - fields = new Object(); - fields['name'] = $('#item_name').val() + fields = {}; + fields['name'] = $('#item_name').val(); fields['description'] = $('#item_description').val(); fields['cost'] = $('#item_cost').val(); fields['quantity'] = $('#item_quantity').val(); @@ -86,7 +107,7 @@ $('body').on('submit', '#item-form', function (e) { fields['order'] = order; - objectitems[pk] = new Object(); + objectitems[pk] = {}; objectitems[pk]['fields'] = fields; // Add the new table @@ -96,7 +117,7 @@ $('body').on('submit', '#item-form', function (e) { // Existing item // update data structure fields = objectitems[pk].fields; - fields.name = $('#item_name').val() + fields.name = $('#item_name').val(); fields.description = $('#item_description').val(); fields.cost = $('#item_cost').val(); fields.quantity = $('#item_quantity').val(); @@ -116,24 +137,3 @@ $('body').on('submit', '#item-form', function (e) { $('body').on('submit', '.itemised_form', function (e) { $('#id_items_json').val(JSON.stringify(objectitems)); }); - -// Return a helper with preserved width of cells -var fixHelper = function (e, ui) { - ui.children().each(function () { - $(this).width($(this).width()); - }); - return ui; -}; - -$("#item-table tbody").sortable({ - helper: fixHelper, - update: function (e, ui) { - info = $(this).sortable("toArray"); - itemorder = new Array(); - $.each(info, function (key, value) { - pk = $('#' + value).data('pk'); - objectitems[pk].fields.order = key; - }); - - } -}); \ No newline at end of file diff --git a/RIGS/templates/RIGS/event_form.html b/RIGS/templates/RIGS/event_form.html index cbcaf83f..44b9a46d 100644 --- a/RIGS/templates/RIGS/event_form.html +++ b/RIGS/templates/RIGS/event_form.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'base_ember.html' %} {% load widget_tweaks %} {% load static %} {% load multiply from filters %} @@ -11,22 +11,6 @@ {% endblock %} {% block content %} -
{% csrf_token %} -
-
-
-

- {% if duplicate %} - Duplicate of Event N{{ object.pk|stringformat:"05d" }} - {% elif object.pk %} - Event N{{ object.pk|stringformat:"05d" }} - {% else %} - New Event - {% endif %} -

-
-
-
- + {% endblock %} diff --git a/app/controllers/event/create.js b/app/controllers/event/create.js new file mode 100644 index 00000000..16c84eee --- /dev/null +++ b/app/controllers/event/create.js @@ -0,0 +1,4 @@ +import Ember from "ember"; +import SetTimeMixin from "pyrigs/mixins/set-time-mixin"; + +export default Ember.Controller.extend(SetTimeMixin, {}); diff --git a/app/controllers/event/duplicate.js b/app/controllers/event/duplicate.js new file mode 100644 index 00000000..16c84eee --- /dev/null +++ b/app/controllers/event/duplicate.js @@ -0,0 +1,4 @@ +import Ember from "ember"; +import SetTimeMixin from "pyrigs/mixins/set-time-mixin"; + +export default Ember.Controller.extend(SetTimeMixin, {}); diff --git a/app/mixins/set-time-mixin.js b/app/mixins/set-time-mixin.js new file mode 100644 index 00000000..1ceadb61 --- /dev/null +++ b/app/mixins/set-time-mixin.js @@ -0,0 +1,23 @@ +import Ember from "ember"; + +export default Ember.Mixin.create({ + actions: { + setTime23Hours() { + Ember.$('#id_end_time').val('23:00'); + }, + + setTime02Hours() { + var start = Ember.$('#id_start_date'); + var end_date = Ember.$('#id_end_date'); + var end_time = Ember.$('#id_end_time'); + + if (start.val() != '' && start.val() == end_date.val()) { + var new_date = new Date(end_date.val()); + new_date.setDate(new_date.getDate() + 1); + end_date.val(new_date.getISOString()); + } + + end_time.val('02:00'); + }, + } +}); diff --git a/app/router.js b/app/router.js index 0b73664c..3b8a936f 100644 --- a/app/router.js +++ b/app/router.js @@ -1,5 +1,5 @@ -import Ember from 'ember'; -import config from './config/environment'; +import Ember from "ember"; +import config from "./config/environment"; const Router = Ember.Router.extend({ location: config.locationType, @@ -7,6 +7,20 @@ const Router = Ember.Router.extend({ }); Router.map(function () { + this.route('event', function () { + this.route('create'); + this.route('show', { + path: ':id' + }); + this.route('duplicate', { + path: ':id/duplicate' + }); + this.route('edit', { + path: ':id/edit' + }); + }); + + this.route('legacy', {path: '/*wildcard'}); }); export default Router; diff --git a/app/routes/event/create.js b/app/routes/event/create.js new file mode 100644 index 00000000..cccd2b24 --- /dev/null +++ b/app/routes/event/create.js @@ -0,0 +1,3 @@ +import Ember from "ember"; + +export default Ember.Route.extend({}); diff --git a/app/routes/event/edit.js b/app/routes/event/edit.js new file mode 100644 index 00000000..cccd2b24 --- /dev/null +++ b/app/routes/event/edit.js @@ -0,0 +1,3 @@ +import Ember from "ember"; + +export default Ember.Route.extend({}); diff --git a/app/templates/event/create.hbs b/app/templates/event/create.hbs new file mode 100644 index 00000000..4a443d59 --- /dev/null +++ b/app/templates/event/create.hbs @@ -0,0 +1 @@ +{{ partial "event/form" }} \ No newline at end of file diff --git a/app/templates/event/duplicate.hbs b/app/templates/event/duplicate.hbs new file mode 100644 index 00000000..4a443d59 --- /dev/null +++ b/app/templates/event/duplicate.hbs @@ -0,0 +1 @@ +{{ partial "event/form" }} \ No newline at end of file diff --git a/app/templates/event/edit.hbs b/app/templates/event/edit.hbs new file mode 100644 index 00000000..306cff62 --- /dev/null +++ b/app/templates/event/edit.hbs @@ -0,0 +1 @@ +{{partial "event/form"}} diff --git a/bower.json b/bower.json index ef99d43f..4f9f0e42 100644 --- a/bower.json +++ b/bower.json @@ -7,6 +7,7 @@ "js-cookie": "^2.1.2", "bootstrap-sass": "^3.3.7", "bootstrap-select": "^1.10.0", - "ajax-bootstrap-select": "^1.3.1" + "ajax-bootstrap-select": "^1.3.1", + "jQuery UI Sortable": "jquery-ui-sortable#*" } } diff --git a/db.sqlite3 b/db.s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kD=okm&&-H#qbts3PCXb6Ym58T~2ZEFC~7K zOMIpbxVLbKA#P!K7Pp{M?jS^Q9p>5U*j~FoHj?T;nC!RHP3eZc4adR*^&|Fh+TJ(t z_27^Z#H~P)5(v=DTIezAB*8)nJv@H`moR+jdR3v94}ot@#mt z3RGPJAD)`42EDnOtH$;`93WE~H)!mYQ3>CxC( zezw3svgZ(H3t+R~po)B1bC#ZD&1R{)mCS+r%9k@2|2EqBCPuBJVhzfy0;YD8fmcJCpxjtX0|Cg7h#-@#R N&Q~MtDxQ;P`CCo6{(}Gj diff --git a/ember-cli-build.js b/ember-cli-build.js index 49b1a4aa..68771fcb 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -27,8 +27,12 @@ module.exports = function (defaults) { // please specify an object with the list of modules as keys // along with the exports of each module as its value. + app.import('bower_components/ember/ember-template-compiler.js'); + app.import('bower_components/bootstrap-select/dist/js/bootstrap-select.js'); app.import('bower_components/ajax-bootstrap-select/dist/js/ajax-bootstrap-select.js'); + app.import('bower_components/jQuery UI Sortable/jquery-ui-sortable.js'); + return app.toTree(); }; diff --git a/templates/base_ember.html b/templates/base_ember.html new file mode 100644 index 00000000..b239f34e --- /dev/null +++ b/templates/base_ember.html @@ -0,0 +1,117 @@ +{% load static from staticfiles %} +{% load raven %} + + + + + + {% block title %}{% endblock %} | Rig Information Gathering System + + + + + + + + + + + {% block css %} + {% endblock %} + + {% block preload_js %} + {% endblock %} + + {% block extra-head %}{% endblock %} + + + + +{% include "analytics.html" %} + + +{% block content %}{% endblock %} + + + + + + + + + + + + +{% block js %} +{% endblock %} + + diff --git a/tests/unit/controllers/event/create-test.js b/tests/unit/controllers/event/create-test.js new file mode 100644 index 00000000..fded0341 --- /dev/null +++ b/tests/unit/controllers/event/create-test.js @@ -0,0 +1,12 @@ +import {moduleFor, test} from "ember-qunit"; + +moduleFor('controller:event/create', 'Unit | Controller | event/create', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +// Replace this with your real tests. +test('it exists', function (assert) { + let controller = this.subject(); + assert.ok(controller); +}); diff --git a/tests/unit/mixins/set-time-mixin-test.js b/tests/unit/mixins/set-time-mixin-test.js new file mode 100644 index 00000000..1f1c0be1 --- /dev/null +++ b/tests/unit/mixins/set-time-mixin-test.js @@ -0,0 +1,12 @@ +import Ember from "ember"; +import SetTimeMixinMixin from "pyrigs/mixins/set-time-mixin"; +import {module, test} from "qunit"; + +module('Unit | Mixin | set time mixin'); + +// Replace this with your real tests. +test('it works', function (assert) { + let SetTimeMixinObject = Ember.Object.extend(SetTimeMixinMixin); + let subject = SetTimeMixinObject.create(); + assert.ok(subject); +}); diff --git a/tests/unit/routes/event/create-test.js b/tests/unit/routes/event/create-test.js new file mode 100644 index 00000000..9c830704 --- /dev/null +++ b/tests/unit/routes/event/create-test.js @@ -0,0 +1,11 @@ +import {moduleFor, test} from "ember-qunit"; + +moduleFor('route:event/create', 'Unit | Route | event/create', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function (assert) { + let route = this.subject(); + assert.ok(route); +}); diff --git a/tests/unit/routes/event/duplicate-test.js b/tests/unit/routes/event/duplicate-test.js new file mode 100644 index 00000000..d2264404 --- /dev/null +++ b/tests/unit/routes/event/duplicate-test.js @@ -0,0 +1,11 @@ +import {moduleFor, test} from "ember-qunit"; + +moduleFor('route:event/duplicate', 'Unit | Route | event/duplicate', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function (assert) { + let route = this.subject(); + assert.ok(route); +}); diff --git a/tests/unit/routes/event/edit-test.js b/tests/unit/routes/event/edit-test.js new file mode 100644 index 00000000..5c13cc66 --- /dev/null +++ b/tests/unit/routes/event/edit-test.js @@ -0,0 +1,11 @@ +import {moduleFor, test} from "ember-qunit"; + +moduleFor('route:event/edit', 'Unit | Route | event/edit', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function (assert) { + let route = this.subject(); + assert.ok(route); +});