modify test.js to use navigateToModel; move code out to xosHelper.js
authorScott Baker <smbaker@gmail.com>
Tue, 4 Nov 2014 07:54:00 +0000 (23:54 -0800)
committerScott Baker <smbaker@gmail.com>
Tue, 4 Nov 2014 07:54:00 +0000 (23:54 -0800)
planetstack/core/xoslib/static/js/test.js

index c0f4146..f657fa3 100644 (file)
@@ -18,7 +18,23 @@ TestApp.addRegions({
     linkedObjs4: "#linkedObjs4"
 });
 
-TestApp.on("start", function() {
+//TestApp.navigateToDetail = function(detailView) {
+//     $(TestApp.detailBoxId).show();\r
+//     TestApp.detail.show(detailView);\r
+//};\r
+\r
+TestApp.navigateToModel = function(app, detailClass, detailNavLink, model) {\r
+\r
+    var detailView = new detailClass({\r
+        model: model,\r
+    });\r
+\r
+    $(app.detailBoxId).show();\r
+    app.detail.show(detailView);\r
+    detailView.showLinkedItems();\r
+};\r
+\r
+TestApp.on("start", function() {\r
      var objs = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
 
      for (var index in objs) {
@@ -29,106 +45,23 @@ TestApp.on("start", function() {
          collection_name = name + "s";
          region_name = name + "List";
 
-         detailClass = Marionette.ItemView.extend({
+         detailClass = XOSDetailView.extend({
             template: detail_template,\r
-            tagName: 'div',\r
-\r
-            events: {"click button.js-submit": "submitClicked",\r
-                     "change input": "inputChanged"},\r
-\r
-            /* inputChanged is watching the onChange events of the input controls. We\r
-               do this to track when this view is 'dirty', so we can throw up a warning\r
-               if the user tries to change his slices without saving first.\r
-            */\r
-\r
-            inputChanged: function(e) {\r
-                this.dirty = true;\r
-            },\r
-\r
-            saveError: function(model, result, xhr) {\r
-                TestApp.showError(result);\r
-            },\r
-\r
-            saveSuccess: function(model, result, xhr) {\r
-                TestApp.showSuccess({status: xhr.xhr.status, statusText: xhr.xhr.statusText});\r
-            },\r
-\r
-            submitClicked: function(e) {\r
-                TestApp.hideError();\r
-                e.preventDefault();\r
-                var data = Backbone.Syphon.serialize(this);\r
-                var thisView = this;\r
-                this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); },\r
-                                       success: function(model, result, xhr) { thisView.saveSuccess(model, result, xhr); }});\r
-                this.dirty = false;\r
-            },\r
-         });
+            app: TestApp,\r
+         });\r
 
-         itemViewClass = Marionette.ItemView.extend({
+         itemViewClass = XOSItemView.extend({
              detailClass: detailClass,
              template: tr_template,
-             tagName: 'tr',
-             className: 'test-tablerow',
-
-             events: {"click": "changeItem"},
-\r
-             changeItem: function(e) {\r
-                    TestApp.hideError();\r
-                    e.preventDefault();\r
-                    e.stopPropagation();\r
-\r
-                    index=0;\r
-                    for (relatedName in this.model.collection.relatedCollections) {\r
-                        relatedField = this.model.collection.relatedCollections[relatedName];\r
-\r
-                        relatedListViewClassName = relatedName + "ListView";\r
-                        if (TestApp[relatedListViewClassName] == undefined) {\r
-                            console.log("warning: " + relatedListViewClassName + " not found");\r
-                        }\r
-                        relatedListViewClass = TestApp[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});\r
-                        TestApp["linkedObjs" + (index+1)].show(new relatedListViewClass());\r
-                        index = index + 1;\r
-                    }\r
-\r
-                    while (index<4) {\r
-                        TestApp["linkedObjs" + (index+1)].empty();\r
-                        index = index + 1;\r
-                    }\r
-\r
-                    var detailView = new this.detailClass({\r
-                        model: this.model,\r
-                    });\r
-                    $('#detailBox').show();\r
-                    TestApp.detail.show(detailView);\r
-              },
+             app: TestApp,
          });
 
-         listViewClass = Marionette.CompositeView.extend({
+         listViewClass = XOSListView.extend({
              childView: itemViewClass,
-             childViewContainer: 'tbody',
              template: table_template,
              collection: xos[collection_name],
              title: name + "s",
-
-             initialize: function() {
-                 this.listenTo(this.collection, 'change', this._renderChildren)
-
-                 // Because many of the templates use idToName(), we need to
-                 // listen to the collections that hold the names for the ids
-                 // that we want to display.
-                 for (i in this.collection.foreignCollections) {
-                     foreignName = this.collection.foreignCollections[i];
-                     if (xos[foreignName] == undefined) {
-                         console.log("Failed to find xos class " + foreignName);
-                     }
-                     this.listenTo(xos[foreignName], 'change', this._renderChildren);
-                     this.listenTo(xos[foreignName], 'sort', this._renderChildren);
-                 }
-             },
-
-             templateHelpers: function() {
-                return { title: this.title };
-             },
+             app: TestApp,
          });
          TestApp[collection_name + "ListView"] = listViewClass;