From 3d8090f9a98cd744bae8764fe5cb6a3a1ea28245 Mon Sep 17 00:00:00 2001 From: Greg Schueler Date: Thu, 21 Apr 2016 16:33:47 -0700 Subject: [PATCH] update messageTemplate binding to allow singluar/plural forms --- .../javascripts/ko/binding-message-template.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rundeckapp/grails-app/assets/javascripts/ko/binding-message-template.js b/rundeckapp/grails-app/assets/javascripts/ko/binding-message-template.js index 3d716af5d84..10b9b3ff9a9 100644 --- a/rundeckapp/grails-app/assets/javascripts/ko/binding-message-template.js +++ b/rundeckapp/grails-app/assets/javascripts/ko/binding-message-template.js @@ -4,6 +4,9 @@ * Placeholders are in the form '{0}','{1}', etc. The "messageTemplate" binding value can be a single value, which * will be used for {0}, or it can be an object with a 'value' property, possibly observable, containing an array * for the replacement values. + * If a binding "messageTemplatePluralize: true" is set, then the template text is treated as a singular and a plural + * version of the same text, separated by "|" character. If the first bound data value is "1", then singular form + * is used, otherwise the plural form is used. * */ ko.bindingHandlers.messageTemplate = { @@ -14,8 +17,15 @@ ko.bindingHandlers.messageTemplate = { return { 'controlsDescendantBindings': true }; }, update:function(element, valueAccessor, allBindings, viewModel, bindingContext){ + var pluralize=allBindings.get('messageTemplatePluralize'); var data=ko.utils.unwrapObservable(valueAccessor()); var template=jQuery(element).data('ko-message-template'); + var pluralTemplate=null; + if(pluralize){ + var arr = template.split('|'); + template = arr[0]; + pluralTemplate = arr[1]; + } var values=[]; if(typeof(data)!='object'){ values=[data]; @@ -30,6 +40,9 @@ ko.bindingHandlers.messageTemplate = { for(var i=0;i=0 && val