X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2FxosDeveloper.js;h=aef640ec2293d8d3877592958097da39f752137c;hb=dee21fb114a2ece37982e47d7b304b92c109cdd6;hp=6ea2d59f631932ccc2fdb507d1cf12cf403f8bd9;hpb=c2404a22f4642b3467bbb5cc7ab5dde2526820ce;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xosDeveloper.js b/planetstack/core/xoslib/static/js/xosDeveloper.js index 6ea2d59..aef640e 100644 --- a/planetstack/core/xoslib/static/js/xosDeveloper.js +++ b/planetstack/core/xoslib/static/js/xosDeveloper.js @@ -1,4 +1,10 @@ -DeveloperApp = new Marionette.Application(); +/* This is an example that uses xoslib + marionette to display the developer + view. + + For an example that uses xoslib + datatables, see xosDeveloper_datatables.js + */ + + DeveloperApp = new Marionette.Application(); DeveloperApp.addRegions({ mainRegion: "#developerView" @@ -10,30 +16,44 @@ DeveloperApp.SliceDetailView = Marionette.ItemView.extend({ className: 'developer_slicedetail' }); -/* -DeveloperApp.SliceListView = Marionette.CollectionView.extend({ +DeveloperApp.SliceListView = Marionette.CompositeView.extend({ tagName: "table", - className: "table table-hover", - template: "#developer-slicetable-template", - childView: DeveloperApp.SliceDetailView, -}); -*/ - -DeveloperApp.SliceListView = Marionette.CompositeView.extend({ - tagName: "table", - className: "table-striped table-bordered", + className: "table table-bordered table-striped", template: "#developer-slicetable-template", childView: DeveloperApp.SliceDetailView, childViewContainer: "tbody", + + events: {"click .sort": "changeSort"}, + + initialize: function() { + this.listenTo(this.collection, 'change', this._renderChildren); + }, + + changeSort: function(e) { + parts=$(e.currentTarget).attr("id").split('-'); + order=parts[1]; + fieldName=parts[2]; + this.collection.sortVar = fieldName; + this.collection.sortOrder = order; + this.collection.sort(); + }, + + attachHtml: function(compositeView, childView, index) { + // The REST API will let admin users see everything. For the developer + // view we still want to hide slices we are not members of. + if (childView.model.get("sliceInfo").roles.length == 0) { + return; + } + DeveloperApp.SliceListView.__super__.attachHtml(compositeView, childView, index); + }, }); DeveloperApp.on("start", function() { var developerSliceListView = new DeveloperApp.SliceListView({ collection: xos.slicesPlus }); - console.log(developerSliceListView); DeveloperApp.mainRegion.show(developerSliceListView); - xos.slicesPlus.startPolling(); //fetch(); + xos.slicesPlus.startPolling(); }); $(document).ready(function(){