add sliceDeployment; add relatedCollections, add filterBy
diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
index cd1c305..1b95c4c 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
@@ -3,6 +3,7 @@
SLIVER_API = "/plstackapi/slivers/";
SLICE_API = "/plstackapi/slices/";
+ SLICEDEPLOYMENT_API = "/plstackapi/slice_deployments/";
NODE_API = "/plstackapi/nodes/";
SITE_API = "/plstackapi/sites/";
USER_API = "/plstackapi/users/";
@@ -14,22 +15,6 @@
SLICEPLUS_API = "/xoslib/slicesplus/";
- function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie != '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // Does this cookie string begin with the name we want?
- if (cookie.substring(0, name.length + 1) == (name + '=')) {
- cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
- break;
- }
- }
- }
- return cookieValue;
- }
-
XOSModel = Backbone.Model.extend({
/* from backbone-tastypie.js */
//idAttribute: 'resource_uri',
@@ -79,6 +64,8 @@
this.sortOrder = 'asc';
},
+ relatedCollections: [],
+
simpleComparator: function( model ){
parts=this.sortVar.split(".");
result = model.get(parts[0]);
@@ -149,6 +136,13 @@
model.fetch(options);
},
+ filterBy: function(fieldName, value) {
+ filtered = this.filter(function(obj) {
+ return obj.get(fieldName) == value;
+ });
+ return new this.constructor(filtered);
+ },
+
/* from backbone-tastypie.js */
url: function( models ) {
var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
@@ -169,7 +163,7 @@
return url;
},
- listMethods: function() {
+ listMethods: function() {
var res = [];
for(var m in this) {
if(typeof this[m] == "function") {
@@ -177,6 +171,10 @@
}
}
return res;
+ },
+
+ templateHelpers: function() {
+ return { title: "foo" };
}
});
@@ -189,9 +187,15 @@
this.slice = XOSModel.extend({ urlRoot: SLICE_API });
this.sliceCollection = XOSCollection.extend({ urlRoot: SLICE_API,
+ relatedCollections: {"slivers": "slice", "sliceDeployments": "slice"},
model: this.slice});
this.slices = new this.sliceCollection();
+ this.sliceDeployment = XOSModel.extend({ urlRoot: SLICEDEPLOYMENT_API });
+ this.sliceDeploymentCollection = XOSCollection.extend({ urlRoot: SLICEDEPLOYMENT_API,
+ model: this.slice});
+ this.sliceDeployments = new this.sliceDeploymentCollection();
+
this.node = XOSModel.extend({ urlRoot: NODE_API });
this.nodeCollection = XOSCollection.extend({ urlRoot: NODE_API,
model: this.node});
@@ -233,7 +237,7 @@
this.services = new this.serviceCollection();
// enhanced REST
- this.slicePlus = XOSModel.extend({ urlRoot: SLICEPLUS_API });
+ this.slicePlus = XOSModel.extend({ urlRoot: SLICEPLUS_API, relatedCollections: {'slivers': "slice"} });
this.slicePlusCollection = XOSCollection.extend({ urlRoot: SLICEPLUS_API,
model: this.slicePlus});
this.slicesPlus = new this.slicePlusCollection();
@@ -243,14 +247,28 @@
xos = new xoslib();
+ function getCookie(name) {
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+
(function() {
var _sync = Backbone.sync;
Backbone.sync = function(method, model, options){
options.beforeSend = function(xhr){
- //var token = $('meta[name="csrf-token"]').attr('content');
var token = getCookie("csrftoken");
xhr.setRequestHeader('X-CSRFToken', token);
- console.log(token);
};
return _sync(method, model, options);
};