blob: 10626d744aa1bac20393a21c94d4d13ef0524bd5 [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();
37};
38
39TestApp.showError = function(result) {
40 $("#errorBox").show();
41 $("#errorBox").html(_.template($("#test-error-template").html())(result));
42 $('#close-error-box').unbind().bind('click', function() {
43 $('#errorBox').hide();
44 });
45};
46
Scott Bakere41c9082014-10-27 23:02:48 -070047TestApp.on("start", function() {
48 var objs = ['deployment', 'image', 'networkTemplate', 'network', 'node', 'service', 'site', 'slice', 'sliver'];
49
50 for (var index in objs) {
51 name = objs[index];
52 tr_template = '#test-' + name + '-listitem-template';
53 table_template = '#test-' + name + '-list-template';
Scott Baker3df41942014-10-28 12:44:13 -070054 detail_template = '#test-' + name + '-detail-template';
Scott Bakere41c9082014-10-27 23:02:48 -070055 collection_name = name + "s";
56 region_name = name + "List";
57
Scott Baker3df41942014-10-28 12:44:13 -070058 detailClass = Marionette.ItemView.extend({
59 template: detail_template,
60 tagName: 'div',
61
62 events: {"click button.js-submit": "submitClicked",
63 "change input": "inputChanged"},
64
65 /* inputChanged is watching the onChange events of the input controls. We
66 do this to track when this view is 'dirty', so we can throw up a warning
67 if the user tries to change his slices without saving first.
68 */
69
70 inputChanged: function(e) {
71 this.dirty = true;
72 },
73
Scott Bakerd044c8f2014-10-28 14:46:13 -070074 saveError: function(model, result, xhr) {
75 TestApp.showError(result);
76 },
77
Scott Baker3df41942014-10-28 12:44:13 -070078 submitClicked: function(e) {
Scott Bakerd044c8f2014-10-28 14:46:13 -070079 TestApp.hideError();
Scott Baker3df41942014-10-28 12:44:13 -070080 e.preventDefault();
81 var data = Backbone.Syphon.serialize(this);
Scott Bakerd044c8f2014-10-28 14:46:13 -070082 var thisView = this;
83 this.model.save(data, {error: function(model, result, xhr) { thisView.saveError(model, result, xhr); }});
Scott Baker3df41942014-10-28 12:44:13 -070084 this.dirty = false;
85 },
86 });
87
Scott Bakere41c9082014-10-27 23:02:48 -070088 itemViewClass = Marionette.ItemView.extend({
Scott Baker3df41942014-10-28 12:44:13 -070089 detailClass: detailClass,
Scott Bakere41c9082014-10-27 23:02:48 -070090 template: tr_template,
91 tagName: 'tr',
92 className: 'test-tablerow',
Scott Baker3df41942014-10-28 12:44:13 -070093
94 events: {"click": "changeItem"},
95
96 changeItem: function(e) {
Scott Bakerd044c8f2014-10-28 14:46:13 -070097 TestApp.hideError();
Scott Baker3df41942014-10-28 12:44:13 -070098 e.preventDefault();
99 e.stopPropagation();
100
101 var detailView = new this.detailClass({
102 model: this.model,
103 });
104 $('#detailBox').show();
105 TestApp.detail.show(detailView);
106 },
Scott Bakere41c9082014-10-27 23:02:48 -0700107 });
108
109 listViewClass = Marionette.CompositeView.extend({
110 childView: itemViewClass,
111 childViewContainer: 'tbody',
112 template: table_template,
113 collection: xos[collection_name],
114
115 initialize: function() {
116 this.listenTo(this.collection, 'change', this._renderChildren)
117 },
118 });
119
120 var listView = new listViewClass();
121
122 TestApp[region_name].show(listView);
123 xos[collection_name].startPolling();
124 }
Scott Baker3df41942014-10-28 12:44:13 -0700125
Scott Bakerd044c8f2014-10-28 14:46:13 -0700126 $('#close-detail-view').unbind().bind('click', function() {
Scott Baker3df41942014-10-28 12:44:13 -0700127 $('#detailBox').hide();
128 });
129
Scott Bakerd044c8f2014-10-28 14:46:13 -0700130// $('#detailBox').hide();
131// $('#errorBox').hide();
Scott Bakere41c9082014-10-27 23:02:48 -0700132});
133
134$(document).ready(function(){
135 TestApp.start();
136});
137