1 SLIVER_API = "/plstackapi/slivers/";
3 XOSModel = Backbone.Model.extend({
4 /* from backbone-tastypie.js */
5 idAttribute: 'resource_uri',
7 /* from backbone-tastypie.js */
9 // Use the id if possible
12 // If there's no idAttribute, try to have the collection construct a url. Fallback to 'urlRoot'.
14 url = this.collection && ( _.isFunction( this.collection.url ) ? this.collection.url() : this.collection.url );
16 url = url || this.urlRoot;
19 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
21 url && ( url += "?no_hyperlinks=1" );
27 XOSCollection = Backbone.Collection.extend({
29 return this.models.map(function(element) { return element.attributes; });
32 maybeFetch: function(options){
33 // Helper function to fetch only if this collection has not been fetched before.
35 // If this has already been fetched, call the success, if it exists
36 options.success && options.success();
37 console.log("alreadyFetched");
41 // when the original success function completes mark this collection as fetched
43 successWrapper = function(success){
46 success && success.apply(this, arguments);
49 options.success = successWrapper(options.success);
50 console.log("call fetch");
54 getOrFetch: function(id, options){
55 // Helper function to use this collection as a cache for models on the server
56 var model = this.get(id);
59 options.success && options.success(model);
63 model = new this.model({
70 /* from backbone-tastypie.js */
71 url: function( models ) {
72 var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
73 url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
75 // Build a url to retrieve a set of models. This assume the last part of each model's idAttribute
76 // (set to 'resource_uri') contains the model's id.
77 if ( models && models.length ) {
78 var ids = _.map( models, function( model ) {
79 var parts = _.compact( model.id.split('/') );
80 return parts[ parts.length - 1 ];
82 url += 'set/' + ids.join(';') + '/';
85 url && ( url += "?no_hyperlinks=1" );
92 this.sliver = XOSModel.extend({ urlRoot: SLIVER_API });
93 this.sliverCollection = XOSCollection.extend({ urlRoot: SLIVER_API,
95 this.slivers = new this.sliverCollection();
98 XOSLib = new xoslib();