tenantview without navigation
authorScott Baker <smbaker@gmail.com>
Mon, 12 Jan 2015 20:37:38 +0000 (12:37 -0800)
committerScott Baker <smbaker@gmail.com>
Mon, 12 Jan 2015 20:37:38 +0000 (12:37 -0800)
planetstack/core/xoslib/dashboards/xosTenant.html
planetstack/core/xoslib/static/js/xosTenant.js
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
planetstack/core/xoslib/static/js/xoslib/xosHelper.js

index 49236d4..42a41e0 100644 (file)
   Are you sure about this?\r
 </div>
 
+<div id="tenant-addslice-dialog" title="Add Child">
+<div id="tenant-addslice-interior"></div>\r
+</div>
+
 <div id="xos-error-dialog" title="Error Message">
 </div>\r
 \r
index 5095505..6f73046 100644 (file)
@@ -38,6 +38,7 @@ XOSTenantButtonView = Marionette.ItemView.extend({
                      },
 
             createClicked: function(e) {
+                     XOSTenantApp.addSlice();
                      },
 
             deleteClicked: function(e) {
@@ -55,7 +56,8 @@ XOSTenantButtonView = Marionette.ItemView.extend({
 XOSTenantApp = new XOSApplication({
     logTableId: "#logTable",
     statusMsgId: "#statusMsg",
-    hideTabsByDefault: true
+    hideTabsByDefault: true,
+    varName: "XOSTenantApp",
 });
 
 XOSTenantApp.addRegions({
@@ -63,9 +65,10 @@ XOSTenantApp.addRegions({
     tenantSummary: "#tenantSummary",
     tenantSiteList: "#tenantSiteList",
     tenantButtons: "#tenantButtons",
+    tenantAddSliceInterior: "#tenant-addslice-interior",
 });
 
-XOSTenantApp.buildViews = function() {\r
+XOSTenantApp.buildViews = function() {
      XOSTenantApp.tenantSites = new XOSTenantSiteCollection();\r
 \r
      tenantSummaryClass = XOSDetailView.extend({template: "#xos-detail-template",\r
@@ -74,6 +77,12 @@ XOSTenantApp.buildViews = function() {
 \r
      XOSTenantApp.tenantSummaryView = tenantSummaryClass;\r
 \r
+     tenantAddClass = XOSDetailView.extend({template: "#xos-detail-template",\r
+                                                app: XOSTenantApp,\r
+                                                detailFields: ["name", "description"]});\r
+\r
+     XOSTenantApp.tenantAddView = tenantAddClass;\r
+\r
      tenantSiteItemClass = XOSItemView.extend({template: "#xos-listitem-template",\r
                                                app: XOSTenantApp});\r
 \r
@@ -92,8 +101,7 @@ XOSTenantApp.buildViews = function() {
 \r
      XOSTenantApp.tenantSliceSelectorView = SliceSelectorView.extend( {\r
          sliceChanged: function(id) {\r
-             //console.log("navigate to " + id);\r
-             XOSTenantApp.Router.navigate("slice/" + id, {trigger: true});\r
+             XOSTenantApp.navToSlice(id);\r
          },\r
      });\r
 \r
@@ -113,6 +121,41 @@ make_choices = function(list_of_names, list_of_values) {
     return result;\r
 };\r
 \r
+XOSTenantApp.navToSlice = function(id) {\r
+    XOSTenantApp.viewSlice(xos.slicesPlus.get(id));\r
+};\r
+\r
+XOSTenantApp.adjustCollectionField = function(collectionName, id, fieldName, amount) {\r
+    model = XOSTenantApp[collectionName].get(id);\r
+    model.set(fieldName, Math.max(model.get(fieldName) + amount, 0));\r
+};\r
+\r
+XOSTenantApp.addSlice = function() {\r
+    var app=this;\r
+    model = new xos.slicesPlus.model({site: xos.tenant().current_user_site_id});\r
+    console.log(model);\r
+    var detailView = new XOSTenantApp.tenantAddView({model: model, collection: xos.slicesPlus});\r
+    detailView.dialog = $("tenant-addslice-dialog");\r
+    app.tenantAddSliceInterior.show(detailView);\r
+    $("#tenant-addslice-dialog").dialog({\r
+       autoOpen: false,
+       modal: true,
+       width: 640,
+       buttons : {
+            "Save" : function() {
+              var addDialog = this;
+              detailView.synchronous = true;
+              detailView.afterSave = function() { $(addDialog).dialog("close"); XOSTenantApp.navToSlice(detailView.model.id); }
+              detailView.save();
+            },
+            "Cancel" : function() {
+              $(this).dialog("close");
+            }
+          }
+        });
+    $("#tenant-addslice-dialog").dialog("open");\r
+};\r
+\r
 XOSTenantApp.viewSlice = function(model) {\r
     if (!model && xos.slicesPlus.models.length > 0) {\r
         model = xos.slicesPlus.models[0];\r
@@ -142,42 +185,6 @@ XOSTenantApp.viewSlice = function(model) {
                                                                 linkedView: tenantSummary } ) );\r
 };\r
 \r
-XOSTenantApp.initRouter = function() {\r
-    router = XOSRouter;\r
-    var api = {};\r
-    var routes = {};\r
-\r
-    nav_url = "slice/:id";\r
-    api_command = "viewSlice";\r
-    api[api_command] = function(id) { XOSTenantApp.viewSlice(xos.slicesPlus.get(id)); };\r
-    routes[nav_url] = api_command;\r
-\r
-    nav_url = "increase/:collectionName/:id/:fieldName";\r
-    api_command = "increase";\r
-    api[api_command] = function(collectionName, id, fieldName) {\r
-                           XOSTenantApp.Router.showPreviousURL();\r
-                           model = XOSTenantApp[collectionName].get(id);\r
-                           model.set(fieldName, model.get(fieldName) + 1);\r
-                       };\r
-    routes[nav_url] = api_command;\r
-\r
-    nav_url = "decrease/:collectionName/:id/:fieldName";\r
-    api_command = "decrease";\r
-    api[api_command] = function(collectionName, id, fieldName) {\r
-                           XOSTenantApp.Router.showPreviousURL();\r
-                           model = XOSTenantApp[collectionName].get(id);\r
-                           model.set(fieldName, Math.max(0, model.get(fieldName) - 1));\r
-                       };\r
-    routes[nav_url] = api_command;\r
-\r
-    nav_url = "*path";\r
-    api_command = "defaultRoute";\r
-    api[api_command] = function() { XOSTenantApp.viewSlice(undefined); };\r
-    routes[nav_url] = api_command;\r
-\r
-    XOSTenantApp.Router = new router({ appRoutes: routes, controller: api });\r
-};\r
-\r
 XOSTenantApp.startNavigation = function() {\r
     Backbone.history.start();\r
     XOSTenantApp.navigationStarted = true;\r
@@ -188,11 +195,7 @@ XOSTenantApp.collectionLoadChange = function() {
 \r
     if (!XOSTenantApp.navigationStarted) {\r
         if (stats["isLoaded"] + stats["failedLoad"] >= stats["startedLoad"]) {\r
-            XOSTenantApp.startNavigation();\r
-\r
-            //if (xos.slicesPlus.models.length > 0) {\r
-            //    XOSTenantApp.Router.navigate("slice/" + xos.slicesPlus.models[0].id, {trigger:true});\r
-            //}\r
+            XOSTenantApp.viewSlice(undefined);\r
         } else {\r
             $("#tenantSummary").html("<h3>Loading...</h3><div id='xos-startup-progress'></div>");\r
             $("#xos-startup-progress").progressbar({value: stats["completedLoad"], max: stats["startedLoad"]});\r
@@ -203,8 +206,6 @@ XOSTenantApp.collectionLoadChange = function() {
 XOSTenantApp.on("start", function() {\r
      XOSTenantApp.buildViews();
 
-     XOSTenantApp.initRouter();
-
      // fire it once to initially show the progress bar
      XOSTenantApp.collectionLoadChange();
 
index 762a2b5..d359f36 100644 (file)
@@ -398,8 +398,6 @@ if (! window.XOSLIB_LOADED ) {
         if (!modelAttrs.defaults) {
             modelAttrs.defaults = get_defaults(modelName);
         }
-        console.log(modelName);
-        console.log(modelAttrs);
 
 //        if ((typeof xosdefaults !== "undefined") && xosdefaults[modelName]) {
 //            modelAttrs["defaults"] = xosdefaults[modelName];
@@ -694,6 +692,8 @@ if (! window.XOSLIB_LOADED ) {
                             detailFields: [],
                             });
 
+        this.tenant = function() { return this.tenantview.models[0].attributes; }
+
         this.listObjects = function() { return this.allCollectionNames; };
 
         this.getCollectionStatus = function() {
index 0cadf79..4ec75a6 100644 (file)
@@ -8,9 +8,6 @@ SliceSelectorOption = Marionette.ItemView.extend({
     template: "#xos-sliceselector-option",
     tagName: "option",
     attributes: function() {
-        console.log("XXX");
-        console.log(this.options.selectedID);
-        console.log(this.model.get("id"));
         if (this.options.selectedID == this.model.get("id")) {
             return { value: this.model.get("id"), selected: 1 };
         } else {
@@ -881,7 +878,7 @@ XOSDataTableView = Marionette.View.extend( {
                 var foreignCollection = view.collection.foreignFields[fieldName];
                 mSearchText = function(x) { return idToName(x, foreignCollection, "humanReadableName"); };
             } else if (inputType[fieldName] == "spinner") {
-                mRender = function(x,y,z) { return xosDataTableSpinnerTemplate( {value: x, collectionName: view.collection.collectionName, fieldName: fieldName, id: z.id} ); };
+                mRender = function(x,y,z) { return xosDataTableSpinnerTemplate( {value: x, collectionName: view.collection.collectionName, fieldName: fieldName, id: z.id, app: view.app} ); };
             }
             if ($.inArray(fieldName, view.collection.detailLinkFields)>=0) {
                 var collectionName = view.collection.collectionName;