1 SLIVER_API = "/plstackapi/slivers/";
2 SLICE_API = "/plstackapi/slices/";
3 NODE_API = "/plstackapi/nodes/";
4 SITE_API = "/plstackapi/sites/";
5 USER_API = "/plstackapi/users/";
6 DEPLOYMENT_API = "/plstackapi/deployments";
8 SLICEPLUS_API = "/xoslib/slicesplus/";
10 XOSModel = Backbone.Model.extend({
11 /* from backbone-tastypie.js */
12 //idAttribute: 'resource_uri',
14 /* from backbone-tastypie.js */
16 var url = this.attributes.resource_uri;
19 url = this.urlRoot + this.id;
23 // XXX I'm not sure this does anything useful
24 url = ( _.isFunction( this.collection.url ) ? this.collection.url() : this.collection.url );
25 url = url || this.urlRoot;
28 // remove any existing query parameters
29 url && ( url.indexOf("?") > -1 ) && ( url = url.split("?")[0] );
31 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
33 url && ( url += "?no_hyperlinks=1" );
38 listMethods: function() {
40 for(var m in this) {
\r
41 if(typeof this[m] == "function") {
\r
49 XOSCollection = Backbone.Collection.extend({
51 return this.models.map(function(element) { return element.attributes; });
54 startPolling: function() {
57 setInterval(function() { console.log(collection); collection.fetch(); }, 10000);
63 maybeFetch: function(options){
64 // Helper function to fetch only if this collection has not been fetched before.
66 // If this has already been fetched, call the success, if it exists
67 options.success && options.success();
68 console.log("alreadyFetched");
72 // when the original success function completes mark this collection as fetched
74 successWrapper = function(success){
77 success && success.apply(this, arguments);
80 options.success = successWrapper(options.success);
81 console.log("call fetch");
85 getOrFetch: function(id, options){
86 // Helper function to use this collection as a cache for models on the server
87 var model = this.get(id);
90 options.success && options.success(model);
94 model = new this.model({
101 /* from backbone-tastypie.js */
102 url: function( models ) {
103 var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
104 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
106 // Build a url to retrieve a set of models. This assume the last part of each model's idAttribute
107 // (set to 'resource_uri') contains the model's id.
108 if ( models && models.length ) {
109 var ids = _.map( models, function( model ) {
110 var parts = _.compact( model.id.split('/') );
111 return parts[ parts.length - 1 ];
113 url += 'set/' + ids.join(';') + '/';
116 url && ( url += "?no_hyperlinks=1" );
121 listMethods: function() {
123 for(var m in this) {
\r
124 if(typeof this[m] == "function") {
\r
134 this.sliver = XOSModel.extend({ urlRoot: SLIVER_API });
135 this.sliverCollection = XOSCollection.extend({ urlRoot: SLIVER_API,
136 model: this.sliver});
137 this.slivers = new this.sliverCollection();
139 this.slice = XOSModel.extend({ urlRoot: SLICE_API });
140 this.sliceCollection = XOSCollection.extend({ urlRoot: SLICE_API,
142 this.slices = new this.sliceCollection();
144 this.node = XOSModel.extend({ urlRoot: NODE_API });
145 this.nodeCollection = XOSCollection.extend({ urlRoot: NODE_API,
147 this.nodes = new this.nodeCollection();
149 this.site = XOSModel.extend({ urlRoot: SITE_API });
150 this.siteCollection = XOSCollection.extend({ urlRoot: SITE_API,
152 this.sites = new this.siteCollection();
154 this.user = XOSModel.extend({ urlRoot: USER_API });
155 this.userCollection = XOSCollection.extend({ urlRoot: USER_API,
157 this.users = new this.userCollection();
159 this.deployment = XOSModel.extend({ urlRoot: DEPLOYMENT_API });
160 this.deploymentCollection = XOSCollection.extend({ urlRoot: DEPLOYMENT_API,
161 model: this.deployment});
162 this.deployments = new this.deploymentCollection();
165 this.slicePlus = XOSModel.extend({ urlRoot: SLICEPLUS_API });
166 this.slicePlusCollection = XOSCollection.extend({ urlRoot: SLICEPLUS_API,
167 model: this.slicePlus});
168 this.slicesPlus = new this.slicePlusCollection();
170 this.listObjects = function() { return ["slivers", "slices", "nodes", "sites", "users", "deployments"]; };