1 SLIVER_API = "/plstackapi/slivers/";
2 SLICE_API = "/plstackapi/slices/";
4 XOSModel = Backbone.Model.extend({
5 /* from backbone-tastypie.js */
6 idAttribute: 'resource_uri',
8 /* from backbone-tastypie.js */
10 // Use the id if possible
13 // If there's no idAttribute, try to have the collection construct a url. Fallback to 'urlRoot'.
15 url = this.collection && ( _.isFunction( this.collection.url ) ? this.collection.url() : this.collection.url );
17 url = url || this.urlRoot;
20 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
22 url && ( url += "?no_hyperlinks=1" );
28 XOSCollection = Backbone.Collection.extend({
30 return this.models.map(function(element) { return element.attributes; });
33 maybeFetch: function(options){
34 // Helper function to fetch only if this collection has not been fetched before.
36 // If this has already been fetched, call the success, if it exists
37 options.success && options.success();
38 console.log("alreadyFetched");
42 // when the original success function completes mark this collection as fetched
44 successWrapper = function(success){
47 success && success.apply(this, arguments);
50 options.success = successWrapper(options.success);
51 console.log("call fetch");
55 getOrFetch: function(id, options){
56 // Helper function to use this collection as a cache for models on the server
57 var model = this.get(id);
60 options.success && options.success(model);
64 model = new this.model({
71 /* from backbone-tastypie.js */
72 url: function( models ) {
73 var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
74 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
76 // Build a url to retrieve a set of models. This assume the last part of each model's idAttribute
77 // (set to 'resource_uri') contains the model's id.
78 if ( models && models.length ) {
79 var ids = _.map( models, function( model ) {
80 var parts = _.compact( model.id.split('/') );
81 return parts[ parts.length - 1 ];
83 url += 'set/' + ids.join(';') + '/';
86 url && ( url += "?no_hyperlinks=1" );
93 this.sliver = XOSModel.extend({ urlRoot: SLIVER_API });
94 this.sliverCollection = XOSCollection.extend({ urlRoot: SLIVER_API,
96 this.slivers = new this.sliverCollection();
98 this.slice = XOSModel.extend({ urlRoot: SLICE_API });
99 this.sliceCollection = XOSCollection.extend({ urlRoot: SLICE_API,
101 this.slices = new this.sliceCollection();