handle language for multiselect

This commit is contained in:
Nicolas Le Goff
2013-06-11 18:02:30 +02:00
parent 5fe2f4d554
commit 5e7a570a0f
2 changed files with 21 additions and 2 deletions

View File

@@ -189,6 +189,9 @@ class Login implements ControllerProviderInterface
'validation_length_min' => _('This value is too short. It should have %s character or more'), 'validation_length_min' => _('This value is too short. It should have %s character or more'),
'password_match' => _('The passwords do not match.'), 'password_match' => _('The passwords do not match.'),
'accept_tou' => _('You must accept the terms of use.'), 'accept_tou' => _('You must accept the terms of use.'),
'none_selected' => _('None selected'),
'collections' => _('Collections'),
'collection' => _('Collection'),
)); ));
$date = new \DateTime(); $date = new \DateTime();

View File

@@ -10,10 +10,11 @@
define([ define([
"jquery", "jquery",
"underscore", "underscore",
"i18n",
"backbone", "backbone",
"bootstrap", "bootstrap",
"multiselect" "multiselect"
], function($, _, Backbone, bootstrap, multiselect) { ], function($, _, i18n, Backbone, bootstrap, multiselect) {
var initialize = function() { var initialize = function() {
// close alerts // close alerts
$(document).on("click", ".alert .alert-block-close a", function(e){ $(document).on("click", ".alert .alert-block-close a", function(e){
@@ -24,7 +25,22 @@ define([
$("select[multiple='multiple']").multiselect({ $("select[multiple='multiple']").multiselect({
buttonWidth : "100%", buttonWidth : "100%",
buttonClass: 'btn btn-inverse' buttonClass: 'btn btn-inverse',
buttonText: function(options, select) {
if (options.length === 0) {
return i18n.t("none_selected") + '<b class="caret"></b>';
}
else if (options.length > 4) {
return options.length + (options.length > 1 ? i18n.t("collections") : i18n.t("collection")) + ' <b class="caret"></b>';
}
else {
var selected = '';
options.each(function() {
selected += $(this).text() + ', ';
});
return selected.substr(0, selected.length -2) + ' <b class="caret"></b>';
}
}
}); });
}; };