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