1 TestApp = new XOSApplication();
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.on("start", function() {
22 var objs = ['deployment', 'image', 'networkTemplate', 'network', 'networkSliver', 'networkDeployment', 'node', 'service', 'site', 'slice', 'sliceDeployment', 'slicePrivilege', 'sliver', 'user', 'sliceRole', 'userDeployment'];
24 for (var index in objs) {
26 tr_template = '#xosAdmin-' + name + '-listitem-template';
27 table_template = '#xosAdmin-' + name + '-list-template';
28 detail_template = '#xosAdmin-' + name + '-detail-template';
29 collection_name = name + "s";
30 region_name = name + "List";
32 detailClass = Marionette.ItemView.extend({
33 template: detail_template,
\r
36 events: {"click button.js-submit": "submitClicked",
\r
37 "change input": "inputChanged"},
\r
39 /* inputChanged is watching the onChange events of the input controls. We
\r
40 do this to track when this view is 'dirty', so we can throw up a warning
\r
41 if the user tries to change his slices without saving first.
\r
44 inputChanged: function(e) {
\r
48 saveError: function(model, result, xhr) {
\r
49 TestApp.showError(result);
\r
52 saveSuccess: function(model, result, xhr) {
\r
53 TestApp.showSuccess({status: xhr.xhr.status, statusText: xhr.xhr.statusText});
\r
56 submitClicked: function(e) {
\r
57 TestApp.hideError();
\r
59 var data = Backbone.Syphon.serialize(this);
\r
60 var thisView = this;
\r
61 this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); },
\r
62 success: function(model, result, xhr) { thisView.saveSuccess(model, result, xhr); }});
\r
67 itemViewClass = Marionette.ItemView.extend({
68 detailClass: detailClass,
69 template: tr_template,
71 className: 'test-tablerow',
73 events: {"click": "changeItem"},
75 changeItem: function(e) {
\r
76 TestApp.hideError();
\r
78 e.stopPropagation();
\r
81 for (relatedName in this.model.collection.relatedCollections) {
\r
82 relatedField = this.model.collection.relatedCollections[relatedName];
\r
84 relatedListViewClassName = relatedName + "ListView";
\r
85 if (TestApp[relatedListViewClassName] == undefined) {
\r
86 console.log("warning: " + relatedListViewClassName + " not found");
\r
88 relatedListViewClass = TestApp[relatedListViewClassName].extend({collection: xos[relatedName].filterBy(relatedField,this.model.id)});
\r
89 TestApp["linkedObjs" + (index+1)].show(new relatedListViewClass());
\r
94 TestApp["linkedObjs" + (index+1)].empty();
\r
98 var detailView = new this.detailClass({
\r
101 $('#detailBox').show();
\r
102 TestApp.detail.show(detailView);
\r
106 listViewClass = Marionette.CompositeView.extend({
107 childView: itemViewClass,
108 childViewContainer: 'tbody',
109 template: table_template,
110 collection: xos[collection_name],
113 initialize: function() {
114 this.listenTo(this.collection, 'change', this._renderChildren)
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];
121 if (xos[foreignName] == undefined) {
122 console.log("Failed to find xos class " + foreignName);
124 this.listenTo(xos[foreignName], 'change', this._renderChildren);
125 this.listenTo(xos[foreignName], 'sort', this._renderChildren);
129 templateHelpers: function() {
130 return { title: this.title };
133 TestApp[collection_name + "ListView"] = listViewClass;
135 var listView = new listViewClass();
137 if (region_name in TestApp.getRegions()) {
138 TestApp[region_name].show(listView);
140 xos[collection_name].fetch(); //startPolling();
143 $('#close-detail-view').unbind().bind('click', function() {
144 $('#detailBox').hide();
148 $(document).ready(function(){