add polling for developer view
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xos-backbone.js
index b113535..fe918ea 100644 (file)
@@ -5,6 +5,8 @@ SITE_API = "/plstackapi/sites/";
 USER_API = "/plstackapi/users/";
 DEPLOYMENT_API = "/plstackapi/deployments";
 
+SLICEPLUS_API = "/xoslib/slicesplus/";
+
 XOSModel = Backbone.Model.extend({
     /* from backbone-tastypie.js */
     //idAttribute: 'resource_uri',
@@ -49,6 +51,15 @@ XOSCollection = Backbone.Collection.extend({
                 return this.models.map(function(element) { return element.attributes; });
              },
 
+    startPolling: function() {
+        if (!this._polling) {
+            collection=this;
+            setInterval(function() { console.log(collection); collection.fetch(); }, 10000);
+            this._polling=true;
+            this.fetch();
+        }
+    },
+
     maybeFetch: function(options){
             // Helper function to fetch only if this collection has not been fetched before.
         if(this._fetched){
@@ -119,6 +130,7 @@ XOSCollection = Backbone.Collection.extend({
 });
 
 function xoslib() {
+    // basic REST
     this.sliver = XOSModel.extend({ urlRoot: SLIVER_API });
     this.sliverCollection = XOSCollection.extend({ urlRoot: SLIVER_API,
                                                    model: this.sliver});
@@ -149,6 +161,12 @@ function xoslib() {
                                                        model: this.deployment});
     this.deployments = new this.deploymentCollection();
 
+    // enhanced REST
+    this.slicePlus = XOSModel.extend({ urlRoot: SLICEPLUS_API });
+    this.slicePlusCollection = XOSCollection.extend({ urlRoot: SLICEPLUS_API,
+                                                      model: this.slicePlus});
+    this.slicesPlus = new this.slicePlusCollection();
+
     this.listObjects = function() { return ["slivers", "slices", "nodes", "sites", "users", "deployments"]; };
 };