[9324] | 1 | // Adapting the module pattern to prevent namespace polution; it's related to the namespace pattern
|
---|
| 2 | // http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
|
---|
| 3 | // http://stackoverflow.com/questions/881515/javascript-namespace-declaration#answer-3588712
|
---|
| 4 | var OAAS_MODEL = (function (my, Backbone) {
|
---|
| 5 | // ================= MODEL ===================
|
---|
| 6 | my.Job = Backbone.Model.extend({
|
---|
| 7 | idAttribute: "Id",
|
---|
| 8 | defaults: {
|
---|
| 9 | Id: null,
|
---|
| 10 | Name: null,
|
---|
| 11 | Resource: null,
|
---|
| 12 | Group: null,
|
---|
| 13 | DateCreated: null,
|
---|
| 14 | State: 'Waiting',
|
---|
| 15 | Loading: true
|
---|
| 16 | },
|
---|
| 17 | url: function () {
|
---|
| 18 | return '/Job/Job?jobId=' + this.get('Id');
|
---|
| 19 | },
|
---|
| 20 | initialize: function (spec) {
|
---|
| 21 | // waiting or calculating
|
---|
| 22 | this.set({ Loading: spec.State == 0 || spec.State == 1 });
|
---|
| 23 | }
|
---|
| 24 | });
|
---|
| 25 |
|
---|
| 26 | my.JobList = Backbone.Collection.extend({
|
---|
| 27 | url: function () {
|
---|
| 28 | return "/Job/JobList";
|
---|
| 29 | },
|
---|
| 30 | initialize: function (spec) {
|
---|
| 31 | this.listenTo(this, 'sync', this.adjustDate);
|
---|
| 32 | },
|
---|
| 33 | _poll: function () {
|
---|
| 34 | var self = this;
|
---|
| 35 | setTimeout(function () { self.poll() }, 5000);
|
---|
| 36 | },
|
---|
| 37 | poll: function () {
|
---|
| 38 | var self = this;
|
---|
[9350] | 39 | this.fetch({ cache: false, reset: true, success: function () {
|
---|
[9324] | 40 | self._poll();
|
---|
| 41 | }
|
---|
| 42 | });
|
---|
| 43 | },
|
---|
| 44 | adjustDate: function () {
|
---|
| 45 | for (var i = 0; i < this.models.length; i++) {
|
---|
| 46 | // convert the MS date format here
|
---|
| 47 | var date = this.models[i].get('DateCreated');
|
---|
| 48 | // remove /Date(
|
---|
| 49 | if (!(date instanceof Date)) {
|
---|
| 50 | var value = new Date(parseInt(date.substr(6)));
|
---|
| 51 | this.models[i].set('DateCreated', value);
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | this.trigger('updated', this);
|
---|
| 55 | },
|
---|
| 56 | model: my.Job
|
---|
| 57 | });
|
---|
| 58 |
|
---|
| 59 | my.Run = Backbone.Model.extend({
|
---|
| 60 | defaults: {
|
---|
| 61 | id: null,
|
---|
| 62 | name: null,
|
---|
[9362] | 63 | results: null,
|
---|
| 64 | inputs: null,
|
---|
| 65 | algorithmName: null
|
---|
[9324] | 66 | }
|
---|
| 67 | });
|
---|
| 68 |
|
---|
| 69 | my.RunList = Backbone.Collection.extend({
|
---|
| 70 | initialize: function (spec) {
|
---|
| 71 | this.jobId = spec.jobId;
|
---|
| 72 | },
|
---|
| 73 | url: function () {
|
---|
| 74 | return "/Job/RunList?jobId=" + this.jobId;
|
---|
| 75 | },
|
---|
| 76 | model: my.Run
|
---|
| 77 | });
|
---|
| 78 |
|
---|
[9395] | 79 | my.VisualExtension = Backbone.Model.extend({
|
---|
| 80 | defaults: {
|
---|
| 81 | id: null,
|
---|
| 82 | js: null
|
---|
| 83 | },
|
---|
| 84 | url: function () {
|
---|
| 85 | return '/Job/VisualExtension?scenarioId=' + this.get('id');
|
---|
| 86 | }
|
---|
| 87 | });
|
---|
| 88 |
|
---|
[9324] | 89 | return my;
|
---|
| 90 | } (OAAS_MODEL || {}, Backbone)); |
---|