diff --git a/app/assets/javascripts/rails_admin/ra.filter-box.js b/app/assets/javascripts/rails_admin/ra.filter-box.js index b18b2bb49a..889e482eaf 100644 --- a/app/assets/javascripts/rails_admin/ra.filter-box.js +++ b/app/assets/javascripts/rails_admin/ra.filter-box.js @@ -19,90 +19,154 @@ switch(field_type) { case 'boolean': - var control = ''; + control = $('') + .prop('name', value_name) + .append('') + .append($('').prop('selected', field_value == "true").text(RailsAdmin.I18n.t("true"))) + .append($('').prop('selected', field_value == "false").text(RailsAdmin.I18n.t("false"))) + .append('') + .append($('').prop('selected', field_value == "_present").text(RailsAdmin.I18n.t("is_present"))) + .append($('').prop('selected', field_value == "_blank").text(RailsAdmin.I18n.t("is_blank"))); break; case 'date': additional_control = - ' ' + - ' ' + - ''; + $('') + .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none') + .prop('name', value_name + '[]') + .prop('value', field_value[0] || '') + .add( + $('') + .css('display', (field_operator == "between") ? 'inline-block' : 'none') + .prop('name', value_name + '[]') + .prop('value', field_value[1] || '') + ) + .add( + $('') + .css('display', (field_operator == "between") ? 'inline-block' : 'none') + .prop('name', value_name + '[]') + .prop('value', field_value[2] || '') + ); case 'datetime': case 'timestamp': - control = control || '' + control = control || $('') + .prop('name', operator_name) + .append($('').prop('selected', field_operator == "default").text(RailsAdmin.I18n.t("date"))) + .append($('').prop('selected', field_operator == "between").text(RailsAdmin.I18n.t("between_and_"))) + .append($('').prop('selected', field_operator == "today").text(RailsAdmin.I18n.t("today"))) + .append($('').prop('selected', field_operator == "yesterday").text(RailsAdmin.I18n.t("yesterday"))) + .append($('').prop('selected', field_operator == "this_week").text(RailsAdmin.I18n.t("this_week"))) + .append($('').prop('selected', field_operator == "last_week").text(RailsAdmin.I18n.t("last_week"))) + .append('') + .append($('').prop('selected', field_operator == "_not_null").text(RailsAdmin.I18n.t("is_present"))) + .append($('').prop('selected', field_operator == "_null").text(RailsAdmin.I18n.t("is_blank"))); additional_control = additional_control || - ' ' + - ' ' + - ''; + $('') + .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none') + .prop('name', value_name + '[]') + .prop('value', field_value[0] || '') + .add( + $('') + .css('display', (field_operator == "between") ? 'inline-block' : 'none') + .prop('name', value_name + '[]') + .prop('value', field_value[1] || '') + ) + .add( + $('') + .css('display', (field_operator == "between") ? 'inline-block' : 'none') + .prop('name', value_name + '[]') + .prop('value', field_value[2] || '') + ); break; case 'enum': var multiple_values = ((field_value instanceof Array) ? true : false) - control = '' + - ' ' + - ''; + control = $('') + .css('display', multiple_values ? 'none' : 'inline-block') + .prop('name', multiple_values ? undefined : value_name) + .data('name', value_name) + .append('') + .append($('').prop('selected', field_value == "_present").text(RailsAdmin.I18n.t("is_present"))) + .append($('').prop('selected', field_value == "_blank").text(RailsAdmin.I18n.t("is_blank"))) + .append('') + .append(select_options) + .add( + $('') + .css('display', multiple_values ? 'inline-block' : 'none') + .prop('name', multiple_values ? value_name + '[]' : undefined) + .data('name', value_name + '[]') + .append(select_options) + ) + .add( + $('') + .append($('').addClass('icon-' + (multiple_values ? 'minus' : 'plus'))) + ); break; case 'string': case 'text': case 'belongs_to_association': - control = '' - additional_control = ' '; + control = $('') + .prop('value', field_operator) + .prop('name', operator_name) + .append('') + .append($('').prop('selected', field_operator == "like").text(RailsAdmin.I18n.t("contains"))) + .append($('').prop('selected', field_operator == "is").text(RailsAdmin.I18n.t("is_exactly"))) + .append($('').prop('selected', field_operator == "starts_with").text(RailsAdmin.I18n.t("starts_with"))) + .append($('').prop('selected', field_operator == "ends_with").text(RailsAdmin.I18n.t("ends_with"))) + .append('') + .append($('').prop('selected', field_operator == "_present").text(RailsAdmin.I18n.t("is_present"))) + .append($('').prop('selected', field_operator == "_blank").text(RailsAdmin.I18n.t("is_blank"))); + additional_control = $('') + .css('display', field_operator == "_present" || field_operator == "_blank" ? 'none' : 'inline-block') + .prop('name', value_name) + .prop('value', field_value); break; case 'integer': case 'decimal': case 'float': - control = '' + control = $('') + .prop('name', operator_name) + .append($('').prop('selected', field_operator == "default").text(RailsAdmin.I18n.t("number"))) + .append($('').prop('selected', field_operator == "between").text(RailsAdmin.I18n.t("between_and_"))) + .append('') + .append($('').prop('selected', field_operator == "_not_null").text(RailsAdmin.I18n.t("is_present"))) + .append($('').prop('selected', field_operator == "_null").text(RailsAdmin.I18n.t("is_blank"))); additional_control = - ' ' + - ' ' + - ''; + $('') + .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none') + .prop('type', field_type) + .prop('name', value_name + '[]') + .prop('value', field_value[0] || '') + .add( + $('') + .css('display', (field_operator == "between") ? 'inline-block' : 'none') + .prop('type', field_type) + .prop('name', value_name + '[]') + .prop('value', field_value[1] || '') + ) + .add( + $('') + .css('display', (field_operator == "between") ? 'inline-block' : 'none') + .prop('type', field_type) + .prop('name', value_name + '[]') + .prop('value', field_value[2] || '') + ); break; default: - control = ' '; + control = $('') + .prop('name', value_name) + .prop('value', field_value); break; } var $content = $('

') .addClass('filter form-search') - .append('' + field_label + '') - .append(' ' + control + ' ' + (additional_control || '')); + .append( + $('') + .append($('').append('').append(document.createTextNode(field_label))) + ) + .append(' ') + .append(control) + .append(' ') + .append(additional_control); $('#filters_box').append($content); diff --git a/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js b/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js index 3e41a7b918..93b9cdccae 100644 --- a/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +++ b/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js @@ -186,12 +186,13 @@ } if (filtered.length > 0) { widget.collection[0].innerHTML = ''; - var filteredContainer = []; for (i = 0; i < filtered.length; i++) { - var newOptions = ''; - filteredContainer.push(newOptions); + var newOptions = $('') + .prop('value', matches[filtered[i]].id) + .prop('title', matches[filtered[i]].label) + .text(matches[filtered[i]].label); + $(widget.collection[0]).append(newOptions); } - widget.collection[0].innerHTML = filteredContainer.join(""); } else { widget.collection[0].innerHTML = widget.noObjectsPlaceholder; } @@ -212,11 +213,10 @@ var widget = this; this.element.find("option").each(function(i, option) { + widget._cache['o_' + option.value] = {id: option.value, value: $(option).text()}; if (option.selected) { - widget._cache['o_' + option.value] = {id: option.value, value: option.innerHTML}; $(option).clone().appendTo(widget.selection).attr("selected", false).attr("title", $(option).text()); } else { - widget._cache['o_' + option.value] = {id: option.value, value: option.innerHTML}; $(option).clone().appendTo(widget.collection).attr("selected", false).attr("title", $(option).text()); } });