Scott Baker | fdaee92 | 2014-11-03 09:43:23 -0800 | [diff] [blame^] | 1 | TestApp = new XOSApplication(); |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 2 | |
| 3 | TestApp.addRegions({ |
| 4 | deploymentList: "#deploymentList", |
| 5 | imageList: "#imageList", |
| 6 | networkTemplateList: "#networkTemplateList", |
| 7 | networkList: "#networkList", |
| 8 | nodeList: "#nodeList", |
| 9 | serviceList: "#serviceList", |
| 10 | siteList: "#siteList", |
| 11 | sliceList: "#sliceList", |
| 12 | sliverList: "#sliverList", |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 13 | userList: "#userList", |
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 14 | detail: "#detail", |
| 15 | linkedObjs1: "#linkedObjs1", |
| 16 | linkedObjs2: "#linkedObjs2", |
| 17 | linkedObjs3: "#linkedObjs3", |
| 18 | linkedObjs4: "#linkedObjs4" |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 19 | }); |
| 20 | |
| 21 | TestApp.on("start", function() { |
Scott Baker | 586878e | 2014-10-31 16:43:07 -0700 | [diff] [blame] | 22 | var objs = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment']; |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 23 | |
| 24 | for (var index in objs) { |
| 25 | name = objs[index]; |
Scott Baker | 013025a | 2014-10-30 23:50:20 -0700 | [diff] [blame] | 26 | tr_template = '#xosAdmin-' + name + '-listitem-template'; |
| 27 | table_template = '#xosAdmin-' + name + '-list-template'; |
| 28 | detail_template = '#xosAdmin-' + name + '-detail-template'; |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 29 | collection_name = name + "s"; |
| 30 | region_name = name + "List"; |
| 31 | |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 32 | detailClass = Marionette.ItemView.extend({ |
| 33 | template: detail_template,
|
| 34 | tagName: 'div',
|
| 35 |
|
| 36 | events: {"click button.js-submit": "submitClicked",
|
| 37 | "change input": "inputChanged"},
|
| 38 |
|
| 39 | /* inputChanged is watching the onChange events of the input controls. We
|
| 40 | do this to track when this view is 'dirty', so we can throw up a warning
|
| 41 | if the user tries to change his slices without saving first.
|
| 42 | */
|
| 43 |
|
| 44 | inputChanged: function(e) {
|
| 45 | this.dirty = true;
|
| 46 | },
|
| 47 |
|
Scott Baker | d044c8f | 2014-10-28 14:46:13 -0700 | [diff] [blame] | 48 | saveError: function(model, result, xhr) {
|
| 49 | TestApp.showError(result);
|
| 50 | },
|
| 51 |
|
Scott Baker | 33c84ac | 2014-10-28 21:40:20 -0700 | [diff] [blame] | 52 | saveSuccess: function(model, result, xhr) {
|
| 53 | TestApp.showSuccess({status: xhr.xhr.status, statusText: xhr.xhr.statusText});
|
| 54 | },
|
| 55 |
|
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 56 | submitClicked: function(e) {
|
Scott Baker | d044c8f | 2014-10-28 14:46:13 -0700 | [diff] [blame] | 57 | TestApp.hideError();
|
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 58 | e.preventDefault();
|
| 59 | var data = Backbone.Syphon.serialize(this);
|
Scott Baker | d044c8f | 2014-10-28 14:46:13 -0700 | [diff] [blame] | 60 | var thisView = this;
|
Scott Baker | 33c84ac | 2014-10-28 21:40:20 -0700 | [diff] [blame] | 61 | this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); },
|
| 62 | success: function(model, result, xhr) { thisView.saveSuccess(model, result, xhr); }});
|
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 63 | this.dirty = false;
|
| 64 | },
|
| 65 | }); |
| 66 | |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 67 | itemViewClass = Marionette.ItemView.extend({ |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 68 | detailClass: detailClass, |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 69 | template: tr_template, |
| 70 | tagName: 'tr', |
| 71 | className: 'test-tablerow', |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 72 | |
| 73 | events: {"click": "changeItem"}, |
| 74 |
|
| 75 | changeItem: function(e) {
|
Scott Baker | d044c8f | 2014-10-28 14:46:13 -0700 | [diff] [blame] | 76 | TestApp.hideError();
|
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 77 | e.preventDefault();
|
| 78 | e.stopPropagation();
|
| 79 |
|
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 80 | index=0;
|
| 81 | for (relatedName in this.model.collection.relatedCollections) {
|
| 82 | relatedField = this.model.collection.relatedCollections[relatedName];
|
| 83 |
|
Scott Baker | 586878e | 2014-10-31 16:43:07 -0700 | [diff] [blame] | 84 | relatedListViewClassName = relatedName + "ListView";
|
| 85 | if (TestApp[relatedListViewClassName] == undefined) {
|
| 86 | console.log("warning: " + relatedListViewClassName + " not found");
|
| 87 | }
|
| 88 | relatedListViewClass = TestApp[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});
|
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 89 | TestApp["linkedObjs" + (index+1)].show(new relatedListViewClass());
|
| 90 | index = index + 1;
|
| 91 | }
|
| 92 |
|
| 93 | while (index<4) {
|
| 94 | TestApp["linkedObjs" + (index+1)].empty();
|
| 95 | index = index + 1;
|
| 96 | }
|
| 97 |
|
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 98 | var detailView = new this.detailClass({
|
| 99 | model: this.model,
|
| 100 | });
|
| 101 | $('#detailBox').show();
|
| 102 | TestApp.detail.show(detailView);
|
| 103 | }, |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 104 | }); |
| 105 | |
| 106 | listViewClass = Marionette.CompositeView.extend({ |
| 107 | childView: itemViewClass, |
| 108 | childViewContainer: 'tbody', |
| 109 | template: table_template, |
| 110 | collection: xos[collection_name], |
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 111 | title: name + "s", |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 112 | |
| 113 | initialize: function() { |
| 114 | this.listenTo(this.collection, 'change', this._renderChildren) |
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 115 | |
| 116 | // Because many of the templates use idToName(), we need to |
| 117 | // listen to the collections that hold the names for the ids |
| 118 | // that we want to display. |
| 119 | for (i in this.collection.foreignCollections) { |
| 120 | foreignName = this.collection.foreignCollections[i]; |
Scott Baker | 013025a | 2014-10-30 23:50:20 -0700 | [diff] [blame] | 121 | if (xos[foreignName] == undefined) { |
| 122 | console.log("Failed to find xos class " + foreignName); |
| 123 | } |
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 124 | this.listenTo(xos[foreignName], 'change', this._renderChildren); |
| 125 | this.listenTo(xos[foreignName], 'sort', this._renderChildren); |
| 126 | } |
| 127 | }, |
| 128 | |
| 129 | templateHelpers: function() { |
| 130 | return { title: this.title }; |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 131 | }, |
| 132 | }); |
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 133 | TestApp[collection_name + "ListView"] = listViewClass; |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 134 | |
| 135 | var listView = new listViewClass(); |
| 136 | |
Scott Baker | 4aee9a1 | 2014-10-30 00:06:16 -0700 | [diff] [blame] | 137 | if (region_name in TestApp.getRegions()) { |
| 138 | TestApp[region_name].show(listView); |
| 139 | } |
Scott Baker | 33c84ac | 2014-10-28 21:40:20 -0700 | [diff] [blame] | 140 | xos[collection_name].fetch(); //startPolling(); |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 141 | } |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 142 | |
Scott Baker | d044c8f | 2014-10-28 14:46:13 -0700 | [diff] [blame] | 143 | $('#close-detail-view').unbind().bind('click', function() { |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame] | 144 | $('#detailBox').hide(); |
| 145 | }); |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 146 | }); |
| 147 | |
| 148 | $(document).ready(function(){ |
Scott Baker | 013025a | 2014-10-30 23:50:20 -0700 | [diff] [blame] | 149 | TestApp.start(); |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 150 | }); |
| 151 | |