remove debugging code
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xos-backbone.js
index 59645e7..48d6c99 100644 (file)
@@ -51,6 +51,43 @@ XOSCollection = Backbone.Collection.extend({
                 return this.models.map(function(element) { return element.attributes; });
              },
 
+    initialize: function(){
+      this.sortVar = 'name';\r
+      this.sortOrder = 'asc';\r
+    },\r
+\r
+    simpleComparator: function( model ){\r
+      parts=this.sortVar.split(".");\r
+      result = model.get(parts[0]);\r
+      for (index=1; index<parts.length; ++index) {\r
+          result=result[parts[index]];\r
+      }\r
+      return result;\r
+    },\r
+\r
+    comparator: function (left, right) {\r
+        var l = this.simpleComparator(left);\r
+        var r = this.simpleComparator(right);\r
+\r
+        if (l === void 0) return -1;\r
+        if (r === void 0) return 1;\r
+\r
+        if (this.sortOrder=="desc") {\r
+            return l < r ? 1 : l > r ? -1 : 0;\r
+        } else {\r
+            return l < r ? -1 : l > r ? 1 : 0;\r
+        }\r
+    },\r
+\r
+    startPolling: function() {\r
+        if (!this._polling) {
+            collection=this;
+            setInterval(function() { 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){