Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 1 | DeveloperApp = new Marionette.Application(); |
| 2 |
|
| 3 | DeveloperApp.addRegions({
|
| 4 | mainRegion: "#developerView"
|
| 5 | }); |
| 6 | |
| 7 | DeveloperApp.SliceDetailView = Marionette.ItemView.extend({ |
| 8 | template: "#developer-slicedetail-template",
|
| 9 | tagName: 'tr',
|
| 10 | className: 'developer_slicedetail'
|
| 11 | }); |
| 12 | |
Scott Baker | b6e1066 | 2014-07-14 11:15:45 -0700 | [diff] [blame] | 13 | DeveloperApp.SliceListView = Marionette.CompositeView.extend({ |
Scott Baker | db236c3 | 2014-07-13 17:36:19 -0700 | [diff] [blame] | 14 | tagName: "table",
|
Scott Baker | 0393e5d | 2014-07-14 12:24:03 -0700 | [diff] [blame] | 15 | className: "table table-bordered table-striped",
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 16 | template: "#developer-slicetable-template",
|
| 17 | childView: DeveloperApp.SliceDetailView,
|
Scott Baker | db236c3 | 2014-07-13 17:36:19 -0700 | [diff] [blame] | 18 | childViewContainer: "tbody",
|
Scott Baker | b6e1066 | 2014-07-14 11:15:45 -0700 | [diff] [blame] | 19 |
|
| 20 | events: {"click .sort": "changeSort"},
|
| 21 |
|
Scott Baker | bf33eea | 2014-07-14 18:10:09 -0700 | [diff] [blame] | 22 | initialize: function() {
|
| 23 | this.listenTo(this.collection, 'change', this._renderChildren);
|
| 24 | },
|
| 25 |
|
Scott Baker | b6e1066 | 2014-07-14 11:15:45 -0700 | [diff] [blame] | 26 | changeSort: function(e) {
|
| 27 | parts=$(e.currentTarget).attr("id").split('-');
|
| 28 | order=parts[1];
|
| 29 | fieldName=parts[2];
|
| 30 | console.log(fieldName);
|
| 31 | this.collection.sortVar = fieldName;
|
| 32 | this.collection.sortOrder = order;
|
| 33 | this.collection.sort();
|
Scott Baker | 0393e5d | 2014-07-14 12:24:03 -0700 | [diff] [blame] | 34 | },
|
| 35 |
|
| 36 | attachHtml: function(compositeView, childView, index) {
|
| 37 | // The REST API will let admin users see everything. For the developer
|
| 38 | // view we still want to hide slices we are not members of.
|
| 39 | if (childView.model.get("sliceInfo").roles.length == 0) {
|
| 40 | return;
|
| 41 | }
|
| 42 | DeveloperApp.SliceListView.__super__.attachHtml(compositeView, childView, index);
|
| 43 | },
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 44 | });
|
| 45 | |
| 46 | DeveloperApp.on("start", function() { |
| 47 | var developerSliceListView = new DeveloperApp.SliceListView({ |
Scott Baker | db236c3 | 2014-07-13 17:36:19 -0700 | [diff] [blame] | 48 | collection: xos.slicesPlus
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 49 | });
|
| 50 | console.log(developerSliceListView);
|
| 51 | DeveloperApp.mainRegion.show(developerSliceListView);
|
Scott Baker | b6e1066 | 2014-07-14 11:15:45 -0700 | [diff] [blame] | 52 | xos.slicesPlus.startPolling();
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 53 | }); |
| 54 | |
| 55 | $(document).ready(function(){ |
| 56 | DeveloperApp.start(); |
| 57 | }); |
| 58 | |