blob: ff681e8f899b772b0deec82ec30b23147873a678 [file] [log] [blame]
Scott Bakere41c9082014-10-27 23:02:48 -07001TestApp = new Marionette.Application();
2
3TestApp.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 Baker3df41942014-10-28 12:44:13 -070013 userList: "#userList",
14 detail: "#detail"
Scott Bakere41c9082014-10-27 23:02:48 -070015});
16
17// ---- Deployment ----
18
19TestApp.DeploymentListItemView = Marionette.ItemView.extend({
20 template: '#test-deployment-listitem-template',
21 tagName: 'tr',
22 className: 'test-tablerow',
23});
24
25TestApp.DeploymentListView = Marionette.CompositeView.extend({
26 childView: TestApp.DeploymentListItemView,
27 childViewContainer: 'tbody',
28 template: '#test-deployment-list-template',
29
30 initialize: function() {
31 this.listenTo(this.collection, 'change', this._renderChildren)
32 },
33});
34
Scott Bakerd044c8f2014-10-28 14:46:13 -070035TestApp.hideError = function(result) {
36 $("#errorBox").hide();
Scott Baker33c84ac2014-10-28 21:40:20 -070037 $("#successBox").hide();
38};
39
40TestApp.showSuccess = function(result) {
41 $("#successBox").show();
42 $("#successBox").html(_.template($("#test-success-template").html())(result));
43 $('#close-success-box').unbind().bind('click', function() {
44 $('#successBox').hide();
45 });
Scott Bakerd044c8f2014-10-28 14:46:13 -070046};
47
48TestApp.showError = function(result) {
49 $("#errorBox").show();
50 $("#errorBox").html(_.template($("#test-error-template").html())(result));
51 $('#close-error-box').unbind().bind('click', function() {
52 $('#errorBox').hide();
53 });
54};
55
Scott Bakere41c9082014-10-27 23:02:48 -070056TestApp.on("start", function() {
Scott Baker6cea3a12014-10-28 15:06:54 -070057 var objs = ['deployment', 'image', 'networkTemplate', 'network', 'node', 'service', 'site', 'slice', 'sliver', 'user'];
Scott Bakere41c9082014-10-27 23:02:48 -070058
59 for (var index in objs) {
60 name = objs[index];
61 tr_template = '#test-' + name + '-listitem-template';
62 table_template = '#test-' + name + '-list-template';
Scott Baker3df41942014-10-28 12:44:13 -070063 detail_template = '#test-' + name + '-detail-template';
Scott Bakere41c9082014-10-27 23:02:48 -070064 collection_name = name + "s";
65 region_name = name + "List";
66
Scott Baker3df41942014-10-28 12:44:13 -070067 detailClass = Marionette.ItemView.extend({
68 template: detail_template,
69 tagName: 'div',
70
71 events: {"click button.js-submit": "submitClicked",
72 "change input": "inputChanged"},
73
74 /* inputChanged is watching the onChange events of the input controls. We
75 do this to track when this view is 'dirty', so we can throw up a warning
76 if the user tries to change his slices without saving first.
77 */
78
79 inputChanged: function(e) {
80 this.dirty = true;
81 },
82
Scott Bakerd044c8f2014-10-28 14:46:13 -070083 saveError: function(model, result, xhr) {
84 TestApp.showError(result);
85 },
86
Scott Baker33c84ac2014-10-28 21:40:20 -070087 saveSuccess: function(model, result, xhr) {
88 TestApp.showSuccess({status: xhr.xhr.status, statusText: xhr.xhr.statusText});
89 },
90
Scott Baker3df41942014-10-28 12:44:13 -070091 submitClicked: function(e) {
Scott Bakerd044c8f2014-10-28 14:46:13 -070092 TestApp.hideError();
Scott Baker3df41942014-10-28 12:44:13 -070093 e.preventDefault();
94 var data = Backbone.Syphon.serialize(this);
Scott Bakerd044c8f2014-10-28 14:46:13 -070095 var thisView = this;
Scott Baker33c84ac2014-10-28 21:40:20 -070096 this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); },
97 success: function(model, result, xhr) { thisView.saveSuccess(model, result, xhr); }});
Scott Baker3df41942014-10-28 12:44:13 -070098 this.dirty = false;
99 },
100 });
101
Scott Bakere41c9082014-10-27 23:02:48 -0700102 itemViewClass = Marionette.ItemView.extend({
Scott Baker3df41942014-10-28 12:44:13 -0700103 detailClass: detailClass,
Scott Bakere41c9082014-10-27 23:02:48 -0700104 template: tr_template,
105 tagName: 'tr',
106 className: 'test-tablerow',
Scott Baker3df41942014-10-28 12:44:13 -0700107
108 events: {"click": "changeItem"},
109
110 changeItem: function(e) {
Scott Bakerd044c8f2014-10-28 14:46:13 -0700111 TestApp.hideError();
Scott Baker3df41942014-10-28 12:44:13 -0700112 e.preventDefault();
113 e.stopPropagation();
114
115 var detailView = new this.detailClass({
116 model: this.model,
117 });
118 $('#detailBox').show();
119 TestApp.detail.show(detailView);
120 },
Scott Bakere41c9082014-10-27 23:02:48 -0700121 });
122
123 listViewClass = Marionette.CompositeView.extend({
124 childView: itemViewClass,
125 childViewContainer: 'tbody',
126 template: table_template,
127 collection: xos[collection_name],
128
129 initialize: function() {
130 this.listenTo(this.collection, 'change', this._renderChildren)
131 },
132 });
133
134 var listView = new listViewClass();
135
136 TestApp[region_name].show(listView);
Scott Baker33c84ac2014-10-28 21:40:20 -0700137 xos[collection_name].fetch(); //startPolling();
Scott Bakere41c9082014-10-27 23:02:48 -0700138 }
Scott Baker3df41942014-10-28 12:44:13 -0700139
Scott Bakerd044c8f2014-10-28 14:46:13 -0700140 $('#close-detail-view').unbind().bind('click', function() {
Scott Baker3df41942014-10-28 12:44:13 -0700141 $('#detailBox').hide();
142 });
Scott Bakere41c9082014-10-27 23:02:48 -0700143});
144
145$(document).ready(function(){
146 TestApp.start();
147});
148