refresh button working, spinning circle, navigate function, tolerate sites==undefined...
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xos-backbone.js
index 36df6eb..f615c30 100644 (file)
@@ -116,21 +116,27 @@ if (! window.XOSLIB_LOADED ) {
         },\r
 \r
         fetchSuccess: function(collection, response, options) {\r
+            //console.log("fetch succeeded " + collection.modelName);\r
             this.failedLoad = false;\r
+            this.fetching = false;\r
             if (!this.isLoaded) {\r
                 this.isLoaded = true;\r
                 Backbone.trigger("xoslib:collectionLoadChange", this);\r
             }\r
+            this.trigger("fetchStateChange");\r
             if (options["orig_success"]) {\r
                 options["orig_success"](collection, response, options);\r
             }\r
         },\r
 \r
         fetchFailure: function(collection, response, options) {\r
+            //console.log("fetch failed " + collection.modelName);\r
+            this.fetching = false;\r
             if ((!this.isLoaded) && (!this.failedLoad)) {\r
                 this.failedLoad=true;\r
                 Backbone.trigger("xoslib:collectionLoadChange", this);\r
             }\r
+            this.trigger("fetchStateChange");\r
             if (options["orig_failure"]) {\r
                 options["orig_failure"](collection, response, options);\r
             }\r
@@ -138,10 +144,13 @@ if (! window.XOSLIB_LOADED ) {
 \r
         fetch: function(options) {\r
             var self=this;\r
+            this.fetching=true;\r
+            //console.log("fetch " + this.modelName);\r
             if (!this.startedLoad) {\r
                 this.startedLoad=true;\r
                 Backbone.trigger("xoslib:collectionLoadChange", this);\r
             }\r
+            this.trigger("fetchStateChange");\r
             if (options == undefined) {\r
                 options = {};\r
             }\r
@@ -161,6 +170,20 @@ if (! window.XOSLIB_LOADED ) {
             }
         },
 
+        refresh: function(refreshRelated) {
+            if (!this.fetching) {
+                this.fetch();
+            }
+            if (refreshRelated) {
+                for (related in this.relatedCollections) {
+                    related = xos[related];
+                    if (!related.fetching) {
+                        related.fetch();
+                    }
+                }
+            }
+        },
+
         maybeFetch: function(options){
                 // Helper function to fetch only if this collection has not been fetched before.
             if(this._fetched){