// Adapting the module pattern to prevent namespace polution; it's related to the namespace pattern // http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth // http://stackoverflow.com/questions/881515/javascript-namespace-declaration#answer-3588712 var OAAS_MODEL = (function (my, Backbone) { // ================= MODEL =================== my.Job = Backbone.Model.extend({ idAttribute: "Id", defaults: { Id: null, Name: null, Resource: null, Group: null, DateCreated: null, State: 'Waiting', Loading: true }, url: function () { return '/Job/Job?jobId=' + this.get('Id'); }, initialize: function (spec) { // waiting or calculating this.set({ Loading: spec.State == 0 || spec.State == 1 }); } }); my.JobList = Backbone.Collection.extend({ url: function () { return "/Job/JobList"; }, initialize: function (spec) { this.listenTo(this, 'sync', this.adjustDate); }, _poll: function () { var self = this; setTimeout(function () { self.poll() }, 5000); }, poll: function () { var self = this; this.fetch({ cache: false, reset: true, success: function () { self._poll(); } }); }, adjustDate: function () { for (var i = 0; i < this.models.length; i++) { // convert the MS date format here var date = this.models[i].get('DateCreated'); // remove /Date( if (!(date instanceof Date)) { var value = new Date(parseInt(date.substr(6))); this.models[i].set('DateCreated', value); } } this.trigger('updated', this); }, model: my.Job }); my.Run = Backbone.Model.extend({ defaults: { id: null, name: null, results: null, inputs: null, algorithmName: null } }); my.RunList = Backbone.Collection.extend({ initialize: function (spec) { this.jobId = spec.jobId; }, url: function () { return "/Job/RunList?jobId=" + this.jobId; }, model: my.Run }); my.VisualExtension = Backbone.Model.extend({ defaults: { id: null, js: null }, url: function () { return '/Job/VisualExtension?scenarioId=' + this.get('id'); } }); return my; } (OAAS_MODEL || {}, Backbone));