1 TestApp = new Marionette.Application();
4 deploymentList: "#deploymentList",
5 imageList: "#imageList",
6 networkTemplateList: "#networkTemplateList",
7 networkList: "#networkList",
9 serviceList: "#serviceList",
10 siteList: "#siteList",
11 sliceList: "#sliceList",
12 sliverList: "#sliverList",
13 userList: "#userList",
15 linkedObjs1: "#linkedObjs1",
16 linkedObjs2: "#linkedObjs2",
17 linkedObjs3: "#linkedObjs3",
18 linkedObjs4: "#linkedObjs4"
21 TestApp.hideError = function(result) {
22 $("#errorBox").hide();
23 $("#successBox").hide();
26 TestApp.showSuccess = function(result) {
27 $("#successBox").show();
28 $("#successBox").html(_.template($("#test-success-template").html())(result));
29 $('#close-success-box').unbind().bind('click', function() {
30 $('#successBox').hide();
34 TestApp.showError = function(result) {
35 $("#errorBox").show();
36 $("#errorBox").html(_.template($("#test-error-template").html())(result));
37 $('#close-error-box').unbind().bind('click', function() {
38 $('#errorBox').hide();
42 idToName = function(id, collectionName, fieldName) {
43 linkedObject = xos[collectionName].get(id);
44 if (linkedObject == undefined) {
47 return linkedObject.attributes[fieldName];
51 TestApp.on("start", function() {
52 var objs = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
54 for (var index in objs) {
56 tr_template = '#xosAdmin-' + name + '-listitem-template';
57 table_template = '#xosAdmin-' + name + '-list-template';
58 detail_template = '#xosAdmin-' + name + '-detail-template';
59 collection_name = name + "s";
60 region_name = name + "List";
62 detailClass = Marionette.ItemView.extend({
63 template: detail_template,
\r
66 events: {"click button.js-submit": "submitClicked",
\r
67 "change input": "inputChanged"},
\r
69 /* inputChanged is watching the onChange events of the input controls. We
\r
70 do this to track when this view is 'dirty', so we can throw up a warning
\r
71 if the user tries to change his slices without saving first.
\r
74 inputChanged: function(e) {
\r
78 saveError: function(model, result, xhr) {
\r
79 TestApp.showError(result);
\r
82 saveSuccess: function(model, result, xhr) {
\r
83 TestApp.showSuccess({status: xhr.xhr.status, statusText: xhr.xhr.statusText});
\r
86 submitClicked: function(e) {
\r
87 TestApp.hideError();
\r
89 var data = Backbone.Syphon.serialize(this);
\r
90 var thisView = this;
\r
91 this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); },
\r
92 success: function(model, result, xhr) { thisView.saveSuccess(model, result, xhr); }});
\r
97 itemViewClass = Marionette.ItemView.extend({
98 detailClass: detailClass,
99 template: tr_template,
101 className: 'test-tablerow',
103 events: {"click": "changeItem"},
105 changeItem: function(e) {
\r
106 TestApp.hideError();
\r
107 e.preventDefault();
\r
108 e.stopPropagation();
\r
111 for (relatedName in this.model.collection.relatedCollections) {
\r
112 relatedField = this.model.collection.relatedCollections[relatedName];
\r
114 relatedListViewClass = TestApp[relatedName + "ListView"].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});
\r
115 TestApp["linkedObjs" + (index+1)].show(new relatedListViewClass());
\r
120 TestApp["linkedObjs" + (index+1)].empty();
\r
124 var detailView = new this.detailClass({
\r
127 $('#detailBox').show();
\r
128 TestApp.detail.show(detailView);
\r
132 listViewClass = Marionette.CompositeView.extend({
133 childView: itemViewClass,
134 childViewContainer: 'tbody',
135 template: table_template,
136 collection: xos[collection_name],
139 initialize: function() {
140 this.listenTo(this.collection, 'change', this._renderChildren)
142 // Because many of the templates use idToName(), we need to
143 // listen to the collections that hold the names for the ids
144 // that we want to display.
145 for (i in this.collection.foreignCollections) {
146 foreignName = this.collection.foreignCollections[i];
147 if (xos[foreignName] == undefined) {
148 console.log("Failed to find xos class " + foreignName);
150 this.listenTo(xos[foreignName], 'change', this._renderChildren);
151 this.listenTo(xos[foreignName], 'sort', this._renderChildren);
155 templateHelpers: function() {
156 return { title: this.title };
159 TestApp[collection_name + "ListView"] = listViewClass;
161 var listView = new listViewClass();
163 if (region_name in TestApp.getRegions()) {
164 TestApp[region_name].show(listView);
166 xos[collection_name].fetch(); //startPolling();
169 $('#close-detail-view').unbind().bind('click', function() {
170 $('#detailBox').hide();
174 $(document).ready(function(){