blob: 68b9a5826cff7cb0aa661306d0dfd099ce3c8df4 [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];
36 console.log(fieldName);
37 this.collection.sortVar = fieldName;
38 this.collection.sortOrder = order;
39 this.collection.sort();
Scott Baker0393e5d2014-07-14 12:24:03 -070040 },
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 Baker7ee32a02014-07-13 09:52:15 -070050});
51
52DeveloperApp.on("start", function() {
53 var developerSliceListView = new DeveloperApp.SliceListView({
Scott Bakerdb236c32014-07-13 17:36:19 -070054 collection: xos.slicesPlus
Scott Baker7ee32a02014-07-13 09:52:15 -070055 });
56 console.log(developerSliceListView);
57 DeveloperApp.mainRegion.show(developerSliceListView);
Scott Bakerb6e10662014-07-14 11:15:45 -070058 xos.slicesPlus.startPolling();
Scott Baker7ee32a02014-07-13 09:52:15 -070059});
60
61$(document).ready(function(){
62 DeveloperApp.start();
63});
64