From ad1626b4052fb015c0584487f52af0e18c813731 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 29 Jun 2015 16:24:46 +0200 Subject: [PATCH] Added option to order (searchable_)select options 'DESC'. --- .../_application_controller_form.js.coffee | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index 9bceebe26..ba0bd079d 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -2094,7 +2094,14 @@ class App.ControllerForm extends App.Controller _sortOptions: (attribute) -> return if !attribute.options - return if _.isArray( attribute.options ) + + if _.isArray( attribute.options ) + # reverse if we have to exit early, if configured + if attribute.order + if attribute.order == 'DESC' + attribute.options = attribute.options.reverse() + return + options_by_name = [] for i in attribute.options options_by_name.push i['name'].toString().toLowerCase() @@ -2109,6 +2116,11 @@ class App.ControllerForm extends App.Controller options_new.push ii attribute.options = options_new + # do a final reverse, if configured + if attribute.order + if attribute.order == 'DESC' + attribute.options = attribute.options.reverse() + _addNullOption: (attribute) -> return if !attribute.options return if !attribute.nulloption