From 3bfdd1d9eb7e548d24679e3dc54a6f6777e9b6eb Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 27 Jan 2014 21:51:56 -0800 Subject: [PATCH] Fixed sorting of cutoff when allowed list changes --- src/UI/Handlebars/Helpers/EachReverse.js | 20 +++++++++++++++++++ .../backbone.marionette.templates.js | 1 + .../Quality/Profile/EditQualityProfileView.js | 5 ++++- .../EditQualityProfileViewTemplate.html | 4 ++-- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/UI/Handlebars/Helpers/EachReverse.js diff --git a/src/UI/Handlebars/Helpers/EachReverse.js b/src/UI/Handlebars/Helpers/EachReverse.js new file mode 100644 index 000000000..e2e628117 --- /dev/null +++ b/src/UI/Handlebars/Helpers/EachReverse.js @@ -0,0 +1,20 @@ +'use strict'; +define( + [ + 'handlebars' + ], function (Handlebars) { + Handlebars.registerHelper('eachReverse', function (context) { + var options = arguments[arguments.length - 1]; + var ret = ''; + + if (context && context.length > 0) { + for (var i = context.length - 1; i >= 0; i--) { + ret += options.fn(context[i]); + } + } else { + ret = options.inverse(this); + } + + return ret; + }); + }); diff --git a/src/UI/Handlebars/backbone.marionette.templates.js b/src/UI/Handlebars/backbone.marionette.templates.js index 2c589a5cb..6b0ed8ac5 100644 --- a/src/UI/Handlebars/backbone.marionette.templates.js +++ b/src/UI/Handlebars/backbone.marionette.templates.js @@ -10,6 +10,7 @@ define( 'Handlebars/Helpers/Series', 'Handlebars/Helpers/Quality', 'Handlebars/Helpers/System', + 'Handlebars/Helpers/EachReverse', 'Handlebars/Handlebars.Debug' ], function (Templates) { return function () { diff --git a/src/UI/Settings/Quality/Profile/EditQualityProfileView.js b/src/UI/Settings/Quality/Profile/EditQualityProfileView.js index 8e2acad1e..139bb5de2 100644 --- a/src/UI/Settings/Quality/Profile/EditQualityProfileView.js +++ b/src/UI/Settings/Quality/Profile/EditQualityProfileView.js @@ -31,7 +31,10 @@ define( this.availableCollection.comparator = function (model) { return -model.get('weight'); }; this.availableCollection.sort(); - this.allowedCollection = new Backbone.Collection(this.model.get('allowed').reverse()); + this.allowedCollection = new Backbone.Collection(this.model.get('allowed')); + this.allowedCollection.comparator = function (model) { return -model.get('weight'); }; + this.allowedCollection.sort(); + this.allowedCollection.comparator = undefined; }, onRender: function() { diff --git a/src/UI/Settings/Quality/Profile/EditQualityProfileViewTemplate.html b/src/UI/Settings/Quality/Profile/EditQualityProfileViewTemplate.html index 830301855..da9a83ab3 100644 --- a/src/UI/Settings/Quality/Profile/EditQualityProfileViewTemplate.html +++ b/src/UI/Settings/Quality/Profile/EditQualityProfileViewTemplate.html @@ -18,9 +18,9 @@