refresh button working, spinning circle, navigate function, tolerate sites==undefined...
authorScott Baker <smbaker@gmail.com>
Wed, 19 Nov 2014 01:02:07 +0000 (17:02 -0800)
committerScott Baker <smbaker@gmail.com>
Wed, 19 Nov 2014 01:02:07 +0000 (17:02 -0800)
planetstack/core/xoslib/dashboards/xosAdminDashboard.html
planetstack/core/xoslib/static/css/xosAdminSite.css
planetstack/core/xoslib/static/js/xosAdminSite.js
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
planetstack/core/xoslib/static/js/xoslib/xosHelper.js
planetstack/core/xoslib/templates/xosAdmin.html

index 6d60535..99050e1 100644 (file)
 <button class="btn btn-high btn-info btn-xos-contentButtonPanel" onclick="$('button.btn-xos-save-leave').click()">Save</button>
 <button class="btn btn-high btn-xos-contentButtonPanel" onclick="$('button.btn-xos-save-continue').click()">Save and continue editing</button>
 <button class="btn btn-high btn-xos-contentButtonPanel" onclick="$('button.btn-xos-save-another').click()">Save and add another</button>
+<button class="btn btn-danger btn-xos-contentButtonPanel" onclick="$('button.btn-xos-delete').click()">Delete</button>
 </div>
 <div class="box save-box" id="xos-listview-button-box">
+<button class="btn btn-high btn-primary btn-xos-contentButtonPanel" onclick="$('button.btn-xos-refresh').click()">Refresh</button>
 <button class="btn btn-high btn-success btn-xos-contentButtonPanel" onclick="$('button.btn-xos-add').click()">Add</button>
 </div>
 <div class="box" id="logPanel">
index d1b4275..118a7b0 100644 (file)
@@ -66,6 +66,8 @@
     text-decoration:none;
 }
 
+/* these are for the inline list and detail titles */
+
 .xos-list-title {
     display: none;
 }
     display: none;
 }
 
+/* this one goes with contenttitle */
+
+#xos-list-title-spinner {
+    display: none;
+}
+
 /* undo what planetstack.css does to the progressbar */
 #xos-startup-progress .ui-progressbar-value {
     background-color: rgb(204,204,204) !important;
index b5d0f6c..ceb2589 100644 (file)
@@ -26,6 +26,17 @@ XOSAdminApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
      XOSAdminApp.Router.navigate(detailNavLink + "/" + model.id, {trigger: true});
 };\r
 \r
+XOSAdminApp.navigate = function(what, modelName, modelId) {\r
+    collection_name = modelName + "s";\r
+    if (what=="list") {\r
+        XOSAdminApp.Router.navigate(collection_name, {trigger: true})\r
+    } else if (what=="detail") {\r
+        XOSAdminApp.Router.navigate(collection_name + "/" + modelId, {trigger: true})\r
+    } else if (what=="add") {\r
+        XOSAdminApp.Router.navigate("add" + firstCharUpper(modelName), {trigger: true})\r
+    }\r
+}\r
+\r
 ICON_CLASSES = {home: "icon-home", deployments: "icon-deployment", sites: "icon-site", slices: "icon-slice", users: "icon-user"};\r
 \r
 XOSAdminApp.updateNavigationPanel = function() {\r
@@ -56,12 +67,10 @@ XOSAdminApp.buildViews = function() {
          collection_name = name + "s";
          region_name = name + "List";
          detailNavLink = collection_name;
-         listNavLink = collection_name;
 
          detailClass = XOSDetailView.extend({
             template: detail_template,\r
             app: XOSAdminApp,\r
-            listNavLink: listNavLink,\r
          });\r
          XOSAdminApp[collection_name + "DetailView"] = detailClass;\r
 
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){
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
index d543502..bc6ac02 100644 (file)
@@ -35,7 +35,7 @@
 </script>
 
 <script type="text/template" id="xos-title-list">
-  <h3><%= title %></h3>
+  <h3><img src="/static/img/brokencircle.gif" height=16 width=16 id="xos-list-title-spinner"> <%= title %></h3>
 </script>
 
 <script type="text/template" id="xos-title-detail">
        <td colspan=2><button class="btn js-submit btn-xos-detail btn-xos-save-leave">Save</button>
            <button class="btn js-submit btn-xos-detail btn-xos-save-continue">Save and Continue Editing</button>
            <button class="btn js-submit btn-xos-detail btn-xos-save-another">Save and Add Another</button>
+           <button class="btn js-submit btn-xos-detail btn-xos-delete">Delete</button>
        </td>
     </tr>
 </script>
 
 <script type="text/template" id="xos-inline-list-buttons-template">
            <button class="btn js-submit btn-xos-list btn-xos-add">Add</button>
+           <button class="btn js-submit btn-xos-list btn-xos-refresh">Refresh</button>
        </td>
     </tr>
 </script>
@@ -89,7 +91,7 @@
   <td class="objectLink"><%= name %></td>
   <td><%= backend_type %></td>
   <td><%= admin_tenant %></td>
-  <td><%= sites.length %></td>
+  <td><%= typeof sites != 'undefined' && sites.length || 0 %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-deployment-detail-template">