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 maybeFetch: function(options){
55 // Helper function to fetch only if this collection has not been fetched before.
57 // If this has already been fetched, call the success, if it exists
58 options.success && options.success();
59 console.log("alreadyFetched");
63 // when the original success function completes mark this collection as fetched
65 successWrapper = function(success){
68 success && success.apply(this, arguments);
71 options.success = successWrapper(options.success);
72 console.log("call fetch");
76 getOrFetch: function(id, options){
77 // Helper function to use this collection as a cache for models on the server
78 var model = this.get(id);
81 options.success && options.success(model);
85 model = new this.model({
92 /* from backbone-tastypie.js */
93 url: function( models ) {
94 var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
95 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
97 // Build a url to retrieve a set of models. This assume the last part of each model's idAttribute
98 // (set to 'resource_uri') contains the model's id.
99 if ( models && models.length ) {
100 var ids = _.map( models, function( model ) {
101 var parts = _.compact( model.id.split('/') );
102 return parts[ parts.length - 1 ];
104 url += 'set/' + ids.join(';') + '/';
107 url && ( url += "?no_hyperlinks=1" );
112 listMethods: function() {
114 for(var m in this) {
\r
115 if(typeof this[m] == "function") {
\r
125 this.sliver = XOSModel.extend({ urlRoot: SLIVER_API });
126 this.sliverCollection = XOSCollection.extend({ urlRoot: SLIVER_API,
127 model: this.sliver});
128 this.slivers = new this.sliverCollection();
130 this.slice = XOSModel.extend({ urlRoot: SLICE_API });
131 this.sliceCollection = XOSCollection.extend({ urlRoot: SLICE_API,
133 this.slices = new this.sliceCollection();
135 this.node = XOSModel.extend({ urlRoot: NODE_API });
136 this.nodeCollection = XOSCollection.extend({ urlRoot: NODE_API,
138 this.nodes = new this.nodeCollection();
140 this.site = XOSModel.extend({ urlRoot: SITE_API });
141 this.siteCollection = XOSCollection.extend({ urlRoot: SITE_API,
143 this.sites = new this.siteCollection();
145 this.user = XOSModel.extend({ urlRoot: USER_API });
146 this.userCollection = XOSCollection.extend({ urlRoot: USER_API,
148 this.users = new this.userCollection();
150 this.deployment = XOSModel.extend({ urlRoot: DEPLOYMENT_API });
151 this.deploymentCollection = XOSCollection.extend({ urlRoot: DEPLOYMENT_API,
152 model: this.deployment});
153 this.deployments = new this.deploymentCollection();
156 this.slicePlus = XOSModel.extend({ urlRoot: SLICEPLUS_API });
157 this.slicePlusCollection = XOSCollection.extend({ urlRoot: SLICEPLUS_API,
158 model: this.slicePlus});
159 this.slicesPlus = new this.slicePlusCollection();
161 this.listObjects = function() { return ["slivers", "slices", "nodes", "sites", "users", "deployments"]; };