make tenantview method reslient of users with no site, catch users with no site in...
[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       this.collection.sortVar = fieldName;\r
37       this.collection.sortOrder = order;\r
38       this.collection.sort();\r
39   },\r
40 \r
41   attachHtml: function(compositeView, childView, index) {\r
42       // The REST API will let admin users see everything. For the developer\r
43       // view we still want to hide slices we are not members of.\r
44       if (childView.model.get("sliceInfo").roles.length == 0) {\r
45           return;\r
46       }\r
47       DeveloperApp.SliceListView.__super__.attachHtml(compositeView, childView, index);\r
48   },\r
49 });\r
50
51 DeveloperApp.on("start", function() {
52   var developerSliceListView = new DeveloperApp.SliceListView({
53     collection: xos.slicesPlus\r
54   });\r
55   DeveloperApp.mainRegion.show(developerSliceListView);\r
56   xos.slicesPlus.startPolling();\r
57 });
58
59 $(document).ready(function(){
60   DeveloperApp.start();
61 });
62