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 XOSModel = Backbone.Model.extend({
9 /* from backbone-tastypie.js */
10 //idAttribute: 'resource_uri',
12 /* from backbone-tastypie.js */
14 var url = this.attributes.resource_uri;
17 url = this.urlRoot + this.id;
21 // XXX I'm not sure this does anything useful
22 url = ( _.isFunction( this.collection.url ) ? this.collection.url() : this.collection.url );
23 url = url || this.urlRoot;
26 // remove any existing query parameters
27 url && ( url.indexOf("?") > -1 ) && ( url = url.split("?")[0] );
29 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
31 url && ( url += "?no_hyperlinks=1" );
36 listMethods: function() {
38 for(var m in this) {
\r
39 if(typeof this[m] == "function") {
\r
47 XOSCollection = Backbone.Collection.extend({
49 return this.models.map(function(element) { return element.attributes; });
52 maybeFetch: function(options){
53 // Helper function to fetch only if this collection has not been fetched before.
55 // If this has already been fetched, call the success, if it exists
56 options.success && options.success();
57 console.log("alreadyFetched");
61 // when the original success function completes mark this collection as fetched
63 successWrapper = function(success){
66 success && success.apply(this, arguments);
69 options.success = successWrapper(options.success);
70 console.log("call fetch");
74 getOrFetch: function(id, options){
75 // Helper function to use this collection as a cache for models on the server
76 var model = this.get(id);
79 options.success && options.success(model);
83 model = new this.model({
90 /* from backbone-tastypie.js */
91 url: function( models ) {
92 var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
93 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
95 // Build a url to retrieve a set of models. This assume the last part of each model's idAttribute
96 // (set to 'resource_uri') contains the model's id.
97 if ( models && models.length ) {
98 var ids = _.map( models, function( model ) {
99 var parts = _.compact( model.id.split('/') );
100 return parts[ parts.length - 1 ];
102 url += 'set/' + ids.join(';') + '/';
105 url && ( url += "?no_hyperlinks=1" );
110 listMethods: function() {
112 for(var m in this) {
\r
113 if(typeof this[m] == "function") {
\r
122 this.sliver = XOSModel.extend({ urlRoot: SLIVER_API });
123 this.sliverCollection = XOSCollection.extend({ urlRoot: SLIVER_API,
124 model: this.sliver});
125 this.slivers = new this.sliverCollection();
127 this.slice = XOSModel.extend({ urlRoot: SLICE_API });
128 this.sliceCollection = XOSCollection.extend({ urlRoot: SLICE_API,
130 this.slices = new this.sliceCollection();
132 this.node = XOSModel.extend({ urlRoot: NODE_API });
133 this.nodeCollection = XOSCollection.extend({ urlRoot: NODE_API,
135 this.nodes = new this.nodeCollection();
137 this.site = XOSModel.extend({ urlRoot: SITE_API });
138 this.siteCollection = XOSCollection.extend({ urlRoot: SITE_API,
140 this.sites = new this.siteCollection();
142 this.user = XOSModel.extend({ urlRoot: USER_API });
143 this.userCollection = XOSCollection.extend({ urlRoot: USER_API,
145 this.users = new this.userCollection();
147 this.deployment = XOSModel.extend({ urlRoot: DEPLOYMENT_API });
148 this.deploymentCollection = XOSCollection.extend({ urlRoot: DEPLOYMENT_API,
149 model: this.deployment});
150 this.deployments = new this.deploymentCollection();
152 this.listObjects = function() { return ["slivers", "slices", "nodes", "sites", "users", "deployments"]; };