modify test.js to use navigateToModel; move code out to xosHelper.js
diff --git a/planetstack/core/xoslib/static/js/test.js b/planetstack/core/xoslib/static/js/test.js
index c0f4146..f657fa3 100644
--- a/planetstack/core/xoslib/static/js/test.js
+++ b/planetstack/core/xoslib/static/js/test.js
@@ -18,7 +18,23 @@
linkedObjs4: "#linkedObjs4"
});
-TestApp.on("start", function() {
+//TestApp.navigateToDetail = function(detailView) {
+// $(TestApp.detailBoxId).show();
+// TestApp.detail.show(detailView);
+//};
+
+TestApp.navigateToModel = function(app, detailClass, detailNavLink, model) {
+
+ var detailView = new detailClass({
+ model: model,
+ });
+
+ $(app.detailBoxId).show();
+ app.detail.show(detailView);
+ detailView.showLinkedItems();
+};
+
+TestApp.on("start", function() {
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 @@
collection_name = name + "s";
region_name = name + "List";
- detailClass = Marionette.ItemView.extend({
+ detailClass = XOSDetailView.extend({
template: detail_template,
- tagName: 'div',
-
- events: {"click button.js-submit": "submitClicked",
- "change input": "inputChanged"},
-
- /* inputChanged is watching the onChange events of the input controls. We
- do this to track when this view is 'dirty', so we can throw up a warning
- if the user tries to change his slices without saving first.
- */
-
- inputChanged: function(e) {
- this.dirty = true;
- },
-
- saveError: function(model, result, xhr) {
- TestApp.showError(result);
- },
-
- saveSuccess: function(model, result, xhr) {
- TestApp.showSuccess({status: xhr.xhr.status, statusText: xhr.xhr.statusText});
- },
-
- submitClicked: function(e) {
- TestApp.hideError();
- e.preventDefault();
- var data = Backbone.Syphon.serialize(this);
- var thisView = this;
- this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); },
- success: function(model, result, xhr) { thisView.saveSuccess(model, result, xhr); }});
- this.dirty = false;
- },
- });
+ app: TestApp,
+ });
- itemViewClass = Marionette.ItemView.extend({
+ itemViewClass = XOSItemView.extend({
detailClass: detailClass,
template: tr_template,
- tagName: 'tr',
- className: 'test-tablerow',
-
- events: {"click": "changeItem"},
-
- changeItem: function(e) {
- TestApp.hideError();
- e.preventDefault();
- e.stopPropagation();
-
- index=0;
- for (relatedName in this.model.collection.relatedCollections) {
- relatedField = this.model.collection.relatedCollections[relatedName];
-
- relatedListViewClassName = relatedName + "ListView";
- if (TestApp[relatedListViewClassName] == undefined) {
- console.log("warning: " + relatedListViewClassName + " not found");
- }
- relatedListViewClass = TestApp[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});
- TestApp["linkedObjs" + (index+1)].show(new relatedListViewClass());
- index = index + 1;
- }
-
- while (index<4) {
- TestApp["linkedObjs" + (index+1)].empty();
- index = index + 1;
- }
-
- var detailView = new this.detailClass({
- model: this.model,
- });
- $('#detailBox').show();
- TestApp.detail.show(detailView);
- },
+ 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;