Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 1 | TestApp = new Marionette.Application(); |
| 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", |
| 14 | detail: "#detail" |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 15 | }); |
| 16 | |
| 17 | // ---- Deployment ---- |
| 18 | |
| 19 | TestApp.DeploymentListItemView = Marionette.ItemView.extend({ |
| 20 | template: '#test-deployment-listitem-template', |
| 21 | tagName: 'tr', |
| 22 | className: 'test-tablerow', |
| 23 | }); |
| 24 | |
| 25 | TestApp.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 | |
| 35 | TestApp.on("start", function() { |
| 36 | var objs = ['deployment', 'image', 'networkTemplate', 'network', 'node', 'service', 'site', 'slice', 'sliver']; |
| 37 | |
| 38 | for (var index in objs) { |
| 39 | name = objs[index]; |
| 40 | tr_template = '#test-' + name + '-listitem-template'; |
| 41 | table_template = '#test-' + name + '-list-template'; |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame^] | 42 | detail_template = '#test-' + name + '-detail-template'; |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 43 | collection_name = name + "s"; |
| 44 | region_name = name + "List"; |
| 45 | |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame^] | 46 | detailClass = Marionette.ItemView.extend({ |
| 47 | template: detail_template,
|
| 48 | tagName: 'div',
|
| 49 |
|
| 50 | events: {"click button.js-submit": "submitClicked",
|
| 51 | "change input": "inputChanged"},
|
| 52 |
|
| 53 | /* inputChanged is watching the onChange events of the input controls. We
|
| 54 | do this to track when this view is 'dirty', so we can throw up a warning
|
| 55 | if the user tries to change his slices without saving first.
|
| 56 | */
|
| 57 |
|
| 58 | inputChanged: function(e) {
|
| 59 | this.dirty = true;
|
| 60 | },
|
| 61 |
|
| 62 | submitClicked: function(e) {
|
| 63 | e.preventDefault();
|
| 64 | var data = Backbone.Syphon.serialize(this);
|
| 65 | this.model.save(data);
|
| 66 | this.dirty = false;
|
| 67 | },
|
| 68 | }); |
| 69 | |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 70 | itemViewClass = Marionette.ItemView.extend({ |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame^] | 71 | detailClass: detailClass, |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 72 | template: tr_template, |
| 73 | tagName: 'tr', |
| 74 | className: 'test-tablerow', |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame^] | 75 | |
| 76 | events: {"click": "changeItem"}, |
| 77 |
|
| 78 | changeItem: function(e) {
|
| 79 | e.preventDefault();
|
| 80 | e.stopPropagation();
|
| 81 |
|
| 82 | var detailView = new this.detailClass({
|
| 83 | model: this.model,
|
| 84 | });
|
| 85 | $('#detailBox').show();
|
| 86 | TestApp.detail.show(detailView);
|
| 87 | }, |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 88 | }); |
| 89 | |
| 90 | listViewClass = Marionette.CompositeView.extend({ |
| 91 | childView: itemViewClass, |
| 92 | childViewContainer: 'tbody', |
| 93 | template: table_template, |
| 94 | collection: xos[collection_name], |
| 95 | |
| 96 | initialize: function() { |
| 97 | this.listenTo(this.collection, 'change', this._renderChildren) |
| 98 | }, |
| 99 | }); |
| 100 | |
| 101 | var listView = new listViewClass(); |
| 102 | |
| 103 | TestApp[region_name].show(listView); |
| 104 | xos[collection_name].startPolling(); |
| 105 | } |
Scott Baker | 3df4194 | 2014-10-28 12:44:13 -0700 | [diff] [blame^] | 106 | |
| 107 | $('#close-detail-view').bind('click', function() { |
| 108 | $('#detailBox').hide(); |
| 109 | }); |
| 110 | |
| 111 | $('#detailBox').hide(); |
Scott Baker | e41c908 | 2014-10-27 23:02:48 -0700 | [diff] [blame] | 112 | }); |
| 113 | |
| 114 | $(document).ready(function(){ |
| 115 | TestApp.start();
|
| 116 | }); |
| 117 | |