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];
|
| 36 | console.log(fieldName);
|
| 37 | this.collection.sortVar = fieldName;
|
| 38 | this.collection.sortOrder = order;
|
| 39 | this.collection.sort();
|
Scott Baker | 0393e5d | 2014-07-14 12:24:03 -0700 | [diff] [blame] | 40 | },
|
| 41 |
|
| 42 | attachHtml: function(compositeView, childView, index) {
|
| 43 | // The REST API will let admin users see everything. For the developer
|
| 44 | // view we still want to hide slices we are not members of.
|
| 45 | if (childView.model.get("sliceInfo").roles.length == 0) {
|
| 46 | return;
|
| 47 | }
|
| 48 | DeveloperApp.SliceListView.__super__.attachHtml(compositeView, childView, index);
|
| 49 | },
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 50 | });
|
| 51 | |
| 52 | DeveloperApp.on("start", function() { |
| 53 | var developerSliceListView = new DeveloperApp.SliceListView({ |
Scott Baker | db236c3 | 2014-07-13 17:36:19 -0700 | [diff] [blame] | 54 | collection: xos.slicesPlus
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 55 | });
|
| 56 | console.log(developerSliceListView);
|
| 57 | DeveloperApp.mainRegion.show(developerSliceListView);
|
Scott Baker | b6e1066 | 2014-07-14 11:15:45 -0700 | [diff] [blame] | 58 | xos.slicesPlus.startPolling();
|
Scott Baker | 7ee32a0 | 2014-07-13 09:52:15 -0700 | [diff] [blame] | 59 | }); |
| 60 | |
| 61 | $(document).ready(function(){ |
| 62 | DeveloperApp.start(); |
| 63 | }); |
| 64 | |