refresh button working, spinning circle, navigate function, tolerate sites==undefined...
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xosHelper.js
index 89d0d3b..6de351b 100644 (file)
@@ -128,7 +128,7 @@ XOSApplication = Marionette.Application.extend({
         return function() {\r
             model = new xos[collection_name].model();\r
             detailViewClass = app[detailName];\r
-            detailView = new detailViewClass({model: model});\r
+            detailView = new detailViewClass({model: model, collection:xos[collection_name]});\r
             app[regionName].show(detailView);\r
             $("#xos-detail-button-box").show();\r
             $("#xos-listview-button-box").hide();\r
@@ -203,14 +203,14 @@ XOSDetailView = Marionette.ItemView.extend({
                 console.log("saveLeave");
                 e.preventDefault();
                 this.save();
-                this.app.Router.navigate(this.listNavLink, {trigger: true});
-                console.log("route to " + this.listNavLink);
+                this.app.navigate("list", this.model.modelName);
             },
 
             submitAddAnotherClicked: function(e) {
                 console.log("saveAnother");
                 e.preventDefault();
                 this.save();
+                this.app.navigate("add", this.model.modelName);
             },
 
             save: function() {
@@ -218,8 +218,14 @@ XOSDetailView = Marionette.ItemView.extend({
                 var infoMsgId = this.app.showInformational( {what: "save " + this.model.__proto__.modelName, status: "", statusText: "in progress..."} );\r
                 var data = Backbone.Syphon.serialize(this);\r
                 var that = this;\r
+                var isNew = !this.model.id;\r
                 this.model.save(data, {error: function(model, result, xhr) { that.saveError(model,result,xhr,infoMsgId);},\r
                                        success: function(model, result, xhr) { that.saveSuccess(model,result,xhr,infoMsgId);}});\r
+                if (isNew) {\r
+                    console.log(this.model);\r
+                    this.collection.add(this.model);\r
+                    this.collection.sort();\r
+                }\r
                 this.dirty = false;\r
             },
 
@@ -320,16 +326,30 @@ XOSListView = Marionette.CompositeView.extend({
              childViewContainer: 'tbody',\r
 \r
              events: {"click button.btn-xos-add": "addClicked",\r
-                     },
-
+                      "click button.btn-xos-refresh": "refreshClicked",\r
+                     },\r
+\r
+             _fetchStateChange: function() {\r
+                 if (this.collection.fetching) {\r
+                    $("#xos-list-title-spinner").show();\r
+                 } else {\r
+                    $("#xos-list-title-spinner").hide();\r
+                 }\r
+             },\r
+\r
              addClicked: function(e) {
-                console.log("add");
                 e.preventDefault();
                 this.app.Router.navigate("add" + firstCharUpper(this.collection.modelName), {trigger: true});
              },
 \r
-             initialize: function() {\r
-                 this.listenTo(this.collection, 'change', this._renderChildren)
+\r             refreshClicked: function(e) {
+\r                 e.preventDefault();
+\r                 this.collection.refresh(refreshRelated=true);
+\r             },
+\r
+\r             initialize: function() {
+\r                 this.listenTo(this.collection, 'change', this._renderChildren)
+                 this.listenTo(this.collection, 'fetchStateChange', this._fetchStateChange);
 
                  // Because many of the templates use idToName(), we need to
                  // listen to the collections that hold the names for the ids