From b6e1066832744dc5aee07980e1127e68af9b0552 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 14 Jul 2014 11:15:45 -0700 Subject: [PATCH] sorting working --- .../core/xoslib/dashboards/xosDeveloper.html | 12 ++++---- .../core/xoslib/static/js/xosDeveloper.js | 25 +++++++++------- .../xoslib/static/js/xoslib/xos-backbone.js | 30 ++++++++++++++++++- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/planetstack/core/xoslib/dashboards/xosDeveloper.html b/planetstack/core/xoslib/dashboards/xosDeveloper.html index 33d7ee7..dd4076b 100644 --- a/planetstack/core/xoslib/dashboards/xosDeveloper.html +++ b/planetstack/core/xoslib/dashboards/xosDeveloper.html @@ -13,10 +13,10 @@ + <%= name %><%= sliceInfo.roles[0] %><%= sliceInfo.sliverCount %><%= sliceInfo.siteCount %> + diff --git a/planetstack/core/xoslib/static/js/xosDeveloper.js b/planetstack/core/xoslib/static/js/xosDeveloper.js index 6ea2d59..33c8b7d 100644 --- a/planetstack/core/xoslib/static/js/xosDeveloper.js +++ b/planetstack/core/xoslib/static/js/xosDeveloper.js @@ -10,21 +10,24 @@ DeveloperApp.SliceDetailView = Marionette.ItemView.extend({ className: 'developer_slicedetail' }); -/* -DeveloperApp.SliceListView = Marionette.CollectionView.extend({ - tagName: "table", - className: "table table-hover", - template: "#developer-slicetable-template", - childView: DeveloperApp.SliceDetailView, -}); -*/ - -DeveloperApp.SliceListView = Marionette.CompositeView.extend({ +DeveloperApp.SliceListView = Marionette.CompositeView.extend({ tagName: "table", className: "table-striped table-bordered", template: "#developer-slicetable-template", childView: DeveloperApp.SliceDetailView, childViewContainer: "tbody", + + events: {"click .sort": "changeSort"}, + + changeSort: function(e) { + parts=$(e.currentTarget).attr("id").split('-'); + order=parts[1]; + fieldName=parts[2]; + console.log(fieldName); + this.collection.sortVar = fieldName; + this.collection.sortOrder = order; + this.collection.sort(); + } }); DeveloperApp.on("start", function() { @@ -33,7 +36,7 @@ DeveloperApp.on("start", function() { }); console.log(developerSliceListView); DeveloperApp.mainRegion.show(developerSliceListView); - xos.slicesPlus.startPolling(); //fetch(); + xos.slicesPlus.startPolling(); }); $(document).ready(function(){ diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js index fe918ea..5403212 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js @@ -51,7 +51,35 @@ XOSCollection = Backbone.Collection.extend({ return this.models.map(function(element) { return element.attributes; }); }, - startPolling: function() { + initialize: function(){ + this.sortVar = 'name'; + this.sortOrder = 'asc'; + }, + + simpleComparator: function( model ){ + parts=this.sortVar.split("."); + result = model.get(parts[0]); + for (index=1; index r ? -1 : 0; + } else { + return l < r ? -1 : l > r ? 1 : 0; + } + }, + + startPolling: function() { if (!this._polling) { collection=this; setInterval(function() { console.log(collection); collection.fetch(); }, 10000); -- 2.43.0