blob: aef640ec2293d8d3877592958097da39f752137c [file] [log] [blame]
Scott Bakerac868ac2014-07-15 10:29:17 -07001/* 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 Baker7ee32a02014-07-13 09:52:15 -07008
9DeveloperApp.addRegions({
10 mainRegion: "#developerView"
11});
12
13DeveloperApp.SliceDetailView = Marionette.ItemView.extend({
14 template: "#developer-slicedetail-template",
15 tagName: 'tr',
16 className: 'developer_slicedetail'
17});
18
Scott Bakerb6e10662014-07-14 11:15:45 -070019DeveloperApp.SliceListView = Marionette.CompositeView.extend({
Scott Bakerdb236c32014-07-13 17:36:19 -070020 tagName: "table",
Scott Baker0393e5d2014-07-14 12:24:03 -070021 className: "table table-bordered table-striped",
Scott Baker7ee32a02014-07-13 09:52:15 -070022 template: "#developer-slicetable-template",
23 childView: DeveloperApp.SliceDetailView,
Scott Bakerdb236c32014-07-13 17:36:19 -070024 childViewContainer: "tbody",
Scott Bakerb6e10662014-07-14 11:15:45 -070025
26 events: {"click .sort": "changeSort"},
27
Scott Bakerbf33eea2014-07-14 18:10:09 -070028 initialize: function() {
29 this.listenTo(this.collection, 'change', this._renderChildren);
30 },
31
Scott Bakerb6e10662014-07-14 11:15:45 -070032 changeSort: function(e) {
33 parts=$(e.currentTarget).attr("id").split('-');
34 order=parts[1];
35 fieldName=parts[2];
Scott Bakerb6e10662014-07-14 11:15:45 -070036 this.collection.sortVar = fieldName;
37 this.collection.sortOrder = order;
38 this.collection.sort();
Scott Baker0393e5d2014-07-14 12:24:03 -070039 },
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 Baker7ee32a02014-07-13 09:52:15 -070049});
50
51DeveloperApp.on("start", function() {
52 var developerSliceListView = new DeveloperApp.SliceListView({
Scott Bakerdb236c32014-07-13 17:36:19 -070053 collection: xos.slicesPlus
Scott Baker7ee32a02014-07-13 09:52:15 -070054 });
Scott Baker7ee32a02014-07-13 09:52:15 -070055 DeveloperApp.mainRegion.show(developerSliceListView);
Scott Bakerb6e10662014-07-14 11:15:45 -070056 xos.slicesPlus.startPolling();
Scott Baker7ee32a02014-07-13 09:52:15 -070057});
58
59$(document).ready(function(){
60 DeveloperApp.start();
61});
62