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.sqlite3 index 7bb70cc1..ee4e49e1 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ 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); +});