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