replace the onclick itemview handler with a naviation/template based one
authorScott Baker <smbaker@gmail.com>
Tue, 2 Dec 2014 18:49:04 +0000 (10:49 -0800)
committerScott Baker <smbaker@gmail.com>
Tue, 2 Dec 2014 18:49:04 +0000 (10:49 -0800)
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
planetstack/core/xoslib/static/js/xoslib/xosHelper.js
planetstack/core/xoslib/templates/xosAdmin.html

index 918e4a2..e5ca413 100644 (file)
@@ -70,6 +70,14 @@ if (! window.XOSLIB_LOADED ) {
                 return res;\r
             },
 
+            /* If a 'validate' method is supplied, then it will be called
+               automatically on save. Unfortunately, save calls neither the
+               'error' nor the 'success' callback if the validator fails.
+
+               For now, we're calling our validator 'xosValidate' so this
+               autoamtic validation doesn't occur.
+            */
+
             xosValidate: function(attrs, options) {
                 errors = {};
                 foundErrors = false;
@@ -88,7 +96,15 @@ if (! window.XOSLIB_LOADED ) {
                     return errors;
                 }
                 // backbone.js semantics -- on successful validate, return nothing
-            }
+            },
+
+            /* uncommenting this would make validate() call xosValidate()
+            validate: function(attrs, options) {
+                r = this.xosValidate(attrs, options);
+                console.log("validate");
+                console.log(r);
+                return r;
+            }, */
     });
 
     XOSCollection = Backbone.Collection.extend({
@@ -295,10 +311,10 @@ if (! window.XOSLIB_LOADED ) {
 
         for (key in attrs) {
             value = attrs[key];
-            if ($.inArray(key, ["urlRoot", "modelName", "validate"])>=0) {
+            if ($.inArray(key, ["urlRoot", "modelName", "collectionName", "validate"])>=0) {
                 modelAttrs[key] = value;
             }
-            if ($.inArray(key, ["urlRoot", "modelName", "relatedCollections", "foreignCollections"])>=0) {
+            if ($.inArray(key, ["urlRoot", "modelName", "collectionName", "relatedCollections", "foreignCollections"])>=0) {
                 collectionAttrs[key] = value;
             }
         }
index 2eb3e42..28f85fd 100644 (file)
@@ -231,6 +231,7 @@ XOSDetailView = Marionette.ItemView.extend({
             },\r
 \r
             saveError: function(model, result, xhr, infoMsgId) {\r
+                console.log("saveError");\r
                 result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;\r
                 result["infoMsgId"] = infoMsgId;\r
                 this.app.showError(result);\r
@@ -306,7 +307,6 @@ XOSDetailView = Marionette.ItemView.extend({
                 var infoMsgId = this.app.showInformational( {what: "save " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );\r
 \r
                 this.model.save(data, {error: function(model, result, xhr) { that.saveError(model,result,xhr,infoMsgId);},\r
-                                       invalid: function(model, result, xhr) { console.log("invalid!"); that.saveError(model,result,xhr,infoMsgId);},\r
                                        success: function(model, result, xhr) { that.saveSuccess(model,result,xhr,infoMsgId, isNew);}});\r
                 /*if (isNew) {\r
                     this.collection.add(this.model);\r
@@ -420,15 +420,9 @@ XOSItemView = Marionette.ItemView.extend({
              tagName: 'tr',
              className: 'test-tablerow',
 
-             events: {"click": "changeItem"},
-
-             changeItem: function(e) {\r
-                    this.app.hideError();\r
-                    e.preventDefault();\r
-                    e.stopPropagation();\r
-\r
-                    this.app.navigateToModel(this.app, this.detailClass, this.detailNavLink, this.model);\r
-             },\r
+             templateHelpers: function() { return { modelName: this.model.modelName,
+                                                    collectionName: this.model.collectionName,
+                                         }},
 });
 
 /* XOSListView:
index 8e0448d..b032e00 100644 (file)
     </tr>
 </script>
 
+<script type="text/template" id="xos-delete-button-template">
+    <a href="#delete?model=<%= modelName %>&id=<%= id %>">delete</a>
+</script>
+
+<script type="text/template" id="xos-delete-button-template">
+    <a href="#delete?model=<%= modelName %>&id=<%= id %>">delete</a>
+</script>
+
+<script type="text/template" id="xos-detail-link-template">
+    <a href="#<%= collectionName %>/<%= id %>"><%= text %></a>
+</script>
+
 <!-- Deployment -->
 
 <script type="text/template" id="xosAdmin-deployment-list-template">
      <th>backend</th>
      <th>admin_tenant</th>
      <th># sites</th>
+     <th>delete</th>
   </tr></thead>
   <tbody></tbody>
   </table>
 
 
 <script type="text/template" id="xosAdmin-deployment-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= backend_type %></td>
   <td><%= admin_tenant %></td>
   <td><%= typeof sites != 'undefined' && sites.length || 0 %></td>
+  <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-deployment-detail-template">
 </script>
 
 <script type="text/template" id="xosAdmin-image-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= disk_format %></td>
   <td><%= container_format %></td>
   <td><%= path %></td>
 
 
 <script type="text/template" id="xosAdmin-networkTemplate-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= description %></td>
   <td><%= visibility %></td>
   <td><%= translation %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-network-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= idToName(template,"networkTemplates","name") %></td>
   <td><%= ports %></td>
   <td><%= labels %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-networkSliver-listitem-template">
-  <td class="objectLink"><%= id %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= idToName(network,"networks","name") %></td>
   <td><%= idToName(sliver,"slivers","name") %></td>
   <td><%= ip %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-networkDeployment-listitem-template">
-  <td class="objectLink"><%= id %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= idToName(network,"networks","name") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
   <td><%= net_id %></td>
 
 
 <script type="text/template" id="xosAdmin-node-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= idToName(site,"sites","name") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
 </script>
 
 
 <script type="text/template" id="xosAdmin-sliceRole-listitem-template">
-  <td class="objectLink"><%= id %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= role %></td>
 </script>
 
 
 
 <script type="text/template" id="xosAdmin-service-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= description %></td>
   <td><%= enabled %></td>
   <td><%= versionNumber %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-site-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= site_url %></td>
   <td><%= enabled %></td>
   <td><%= login_base %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-slice-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= enabled %></td>
   <td><%= omf_friendly %></td>
   <td><%= description %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-sliceDeployment-listitem-template">
-  <td class="objectLink"><%= id %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= idToName(slice,"slices","name") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
   <td><%= tenant_id %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-slicePrivilege-listitem-template">
-  <td class="objectLink"><%= id %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= idToName(user,"users","username") %></td>
   <td><%= idToName(slice,"slices","name") %></td>
   <td><%= idToName(role,"sliceRoles","role") %></td>
 
 
 <script type="text/template" id="xosAdmin-sliver-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= name %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: name}) %></td>
   <td><%= instance_id %></td>
   <td><%= instance_name %></td>
   <td><%= idToName(image,"images","name") %></td>
 
 
 <script type="text/template" id="xosAdmin-user-listitem-template">
-  <td class="objectLink"><%= id %></td>
-  <td class="objectLink"><%= username %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: username}) %></td>
   <td><%= firstname %></td>
   <td><%= lastname %></td>
   <td><%= phone %></td>
 </script>
 
 <script type="text/template" id="xosAdmin-userDeployment-listitem-template">
-  <td class="objectLink"><%= id %></td>
+  <td> <%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: id}) %></td>
   <td><%= idToName(user,"users","username") %></td>
   <td><%= idToName(deployment,"deployments","name") %></td>
   <td><%= kuser_id %></td>
 <script>
 xosInlineDetailButtonsTemplate = _.template($("#xos-inline-detail-buttons-template").html());
 xosInlineListButtonsTemplate = _.template($("#xos-inline-list-buttons-template").html());
+xosDeleteButtonTemplate = _.template($("#xos-delete-button-template").html());
+xosDetailLinkTemplate = _.template($("#xos-detail-link-template").html());
 </script>