Skip to content

Commit

Permalink
Merge 29f830a into 9e1c66e
Browse files Browse the repository at this point in the history
  • Loading branch information
impurist committed Nov 9, 2016
2 parents 9e1c66e + 29f830a commit 9935d86
Show file tree
Hide file tree
Showing 30 changed files with 781 additions and 149 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -30,3 +30,5 @@ tmp/**/*
.idea/*.xml
.sass-cache
nbproject
/.DS_Store
*/**/.DS_Store
@@ -0,0 +1,36 @@
(function (components) {

var helpers = components.helpers;

components.has_many_association_filter_component = function (options) {
var component = {};
if (options.check_boxes) {
component.control = options.checkbox_values.map(function (value) {
return helpers.new_checkbox(value, options);
}).join('\n');
} else {
component.control = '<select style="display:' + helpers.select_input_display(options) + 'class="select-single input-sm form-control">' +
'<option value="_discard">...</option>' +
'<option ' + helpers.present_operator_selected(options) + RailsAdmin.I18n.t("is_present") + '</option>' +
'<option ' + helpers.blank_operator_selected(options) + ' value="_blank">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
'<option disabled="disabled">---------</option>' +
options.select_options +
'</select>' +
'<a href="#" class="switch-select"><i class="icon-' + helpers.plus_or_minus_icon(options.multi_select) + '"></i></a>';
}
return component;
};

components.has_and_belongs_to_many_association_filter_component = function (options) {
return this.has_many_association_filter_component(options);
};

components.belongs_to_association_filter_component = function (options) {
var select_options = options['select_options'];
if (select_options.length > 0) {
return this.has_many_association_filter_component(options);
}
return this.string_filter_component(options);
};

}(FilterBoxComponents));
@@ -0,0 +1,19 @@

(function (components) {

var helpers = components.helpers;

components.boolean_filter_component = function (options) {
var component = {};
component.control = '<select class="input-sm form-control" name="' + options.value_name + '">' +
'<option value="_discard">...</option>' +
'<option value="true"' + true_operator_selected(options) + '>' + RailsAdmin.I18n.t("true") + '</option>' +
'<option value="false"' + false_operator_selected(options) + '>' + RailsAdmin.I18n.t("false") + '</option>' +
'<option disabled="disabled">---------</option>' +
'<option ' + helpers.present_operator_selected(options) + ' value="_present">' + RailsAdmin.I18n.t("is_present") + '</option>' +
'<option ' + helpers.blank_operator_selected(options) + ' value="_blank" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
'</select>';
return component;
};

}(FilterBoxComponents));
@@ -0,0 +1,38 @@
(function (components) {

var helpers = components.helpers;
var shared_elements = components.shared_elements;


components.datetime_filter_component = function (options) {
var component = {};
component.control = '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + options.operator_name + '">' +
shared_elements.between_and_default_options() +
'<option ' + helpers.today_filter_selected(options) + ' value="today">' + RailsAdmin.I18n.t("today") + '</option>' +
'<option ' + helpers.yesterday_operator_selected(options) + ' value="yesterday">' + RailsAdmin.I18n.t("yesterday") + '</option>' +
'<option ' + helpers.this_week_operator_selected(options) + ' value="this_week">' + RailsAdmin.I18n.t("this_week") + '</option>' +
'<option ' + helpers.last_week_operator_selected(options) + ' value="last_week">' + RailsAdmin.I18n.t("last_week") + '</option>' +
'<option disabled="disabled">---------</option>' +
'<option ' + helpers.not_null_operator_selected(options) + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
'<option ' + helpers.null_operator_selected(options) + ' value="_null" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
'</select>';
component.additional_control = '<input size="25" class="datetime additional-fieldset default input-sm form-control" style="display:' + helpers.default_filter_display(options) + ';" type="text" name="' + options.value_name + '[]" value="' + (options.field_value[0] || '') + '" /> ' +
'<input size="25" placeholder="-∞" class="datetime additional-fieldset between input-sm form-control" style="display:' + helpers.between_operator_display(options) + ';" type="text" name="' + options.value_name + '[]" value="' + (options.field_value[1] || '') + '" /> ' +
'<input size="25" placeholder="∞" class="datetime additional-fieldset between input-sm form-control" style="display:' + helpers.between_operator_display(options) + ';" type="text" name="' + options.value_name + '[]" value="' + (options.field_value[2] || '') + '" />';
return component;
};

components.date_filter_component = function (options) {
var component = {};
component.control = this.datetime_filter_component(options).control;
component.additional_control = '<input size="20" class="date additional-fieldset default input-sm form-control" style="display:' + ((!options.field_operator || options.field_operator === "default") ? 'inline-block' : 'none') + ';" type="text" name="' + options.value_name + '[]" value="' + (options.field_value[0] || '') + '" /> ' +
'<input size="20" placeholder="-∞" class="date additional-fieldset between input-sm form-control" style="display:' + helpers.between_operator_display(options) + ';" type="text" name="' + options.value_name + '[]" value="' + (options.field_value[1] || '') + '" /> ' +
'<input size="20" placeholder="∞" class="date additional-fieldset between input-sm form-control" style="display:' + helpers.between_operator_display(options) + ';" type="text" name="' + options.value_name + '[]" value="' + (options.field_value[2] || '') + '" />';
return component;
};

components.timestamp_filter_component = function (options) {
return this.datetime_filter_component(options);
};

}(FilterBoxComponents));
@@ -0,0 +1,7 @@
(function (components) {

components.default_filter_component = function (options) {
return {control: '<input type="text" class="input-sm form-control" name="' + options.value_name + '" value="' + options.field_value + '"/>' }
}

}(FilterBoxComponents));
@@ -0,0 +1,23 @@

(function (components) {

var helpers = components.helpers;

components.enum_filter_component = function (options) {
var component = {};
var multiple_values = (options.field_value instanceof Array);
component.control = '<select style="display:' + (multiple_values ? 'none' : 'inline-block') + '" ' + (multiple_values ? '' : 'name="' + options.value_name + '"') + ' data-name="' + options.value_name + '" class="select-single input-sm form-control">' +
'<option value="_discard">...</option>' +
'<option ' + helpers.present_operator_selected(options) + ' value="_present">' + RailsAdmin.I18n.t("is_present") + '</option>' +
'<option ' + helpers.blank_operator_selected(options) + ' value="_blank">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
'<option disabled="disabled">---------</option>' +
options.select_options +
'</select>' +
'<select multiple="multiple" style="display:' + helpers.multiple_values_display(multiple_values, options) + ' data-name="' + options.value_name + '[]" class="select-multiple input-sm form-control">' +
options.select_options +
'</select> ' +
'<a href="#" class="switch-select"><i class="icon-' + helpers.plus_or_minus_icon(multiple_values) + '"></i></a>';
return component;
}

}(FilterBoxComponents));
@@ -0,0 +1,93 @@
(function (helpers) {

var selected_state = 'selected="selected"';

helpers.like_operator_selected = function (options) {
return (options.field_operator === "like" ? selected_state : '');
};

helpers.is_operator_selected = function (options) {
return (options.field_operator === "is" ? selected_state : '');
};

helpers.starts_with_operstor_selected = function (options) {
return (options.field_operator === "starts_with" ? selected_state : '');
};

helpers.ends_with_operator_selected = function (options) {
return (options.field_operator === "ends_with" ? selected_state : '');
};

helpers.default_operator_selected = function (options) {
return (options.field_operator === "default" ? selected_state : '');
};

helpers.between_operator_selected = function (options) {
return (options.field_operator === "between" ? selected_state : '');
};

helpers.not_null_operator_selected = function (options) {
return (options.field_operator === "_not_null" ? selected_state : '');
};

helpers.null_operator_selected = function (options) {
return (options.field_operator === "_null" ? selected_state : '');
};

helpers.today_operator_selected = function (options) {
return (options.field_operator === "today" ? selected_state : '')
};
helpers.yesterday_operator_selected = function (options) {
return (options.field_operator === "yesterday" ? selected_state : '')
};
helpers.last_week_operator_selected = function (options) {
return (options.field_operator === "last_week" ? selected_state : '')
};
helpers.this_week_operator_selected = function (options) {
return (options.field_operator === "this_week" ? selected_state : '')
};
helpers.true_operator_selected = function (options) {
return (options.field_value === "true" ? selected_state : '');
};
helpers.false_operator_selected = function (options) {
return (options.field_value === "false" ? selected_state : '');
};

helpers.default_filter_display = function (options) {
return ((!options.field_operator || options.field_operator === "default") ? 'inline-block' : 'none');
};

helpers.between_operator_display = function (options) {
return ((options.field_operator === "between") ? 'inline-block' : 'none');
};

helpers.checked = function (value, applied_filters) {
return $.inArray(value[1], applied_filters) !== -1 ? 'checked="checked"' : '';
};

helpers.new_checkbox = function (value, options) {
return '<label class="checkbox-inline" for="' + options.value_name + '[]">' +
'<input style="display:inline-block" name="' + options.value_name + '[]" data-name="' + options.value_name + '[]" class="checkbox input-sm form-control" type="checkbox" value="' + value[1] + '" ' + helpers.checked(value, options.applied_filters) + ' />' +
'' + value[0] +
'</label>';
};

helpers.select_input_display = function (options) {
return (options.multi_select ? 'none' : 'inline-block') + '" ' + (options.multi_select ? '' : 'name="' + options.value_name + '"') + ' data-name="' + options.value_name + ' ';
};

helpers.present_operator_selected = function (options) {
return (options.field_value === "_present" ? 'selected="selected"' : '') + ' value="_present">';
};
helpers.blank_operator_selected = function (options) {
return (options.field_value === "_blank" ? 'selected="selected"' : '');
};
helpers.plus_or_minus_icon = function (multi) {
return (multi ? 'minus' : 'plus');
};

helpers.multiple_values_display = function (multiple_values, options) {
return (multiple_values ? 'inline-block' : 'none') + '" ' + (multiple_values ? 'name="' + options.value_name + '[]"' : '');
};

}(FilterBoxComponents.helpers));
@@ -0,0 +1,33 @@
(function (components) {

var helpers = components.helpers;
var shared_elements = components.shared_elements;

components.number_filter_component = function (options) {
var component = {};
component.control = '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + options.operator_name + '">' +
shared_elements.between_and_default_options(options) +
'<option disabled="disabled">---------</option>' +
'<option ' + helpers.not_null_operator_selected(options) + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
'<option ' + helpers.null_operator_selected(options) + ' value="_null" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
'</select>';
component.additional_control =
'<input class="additional-fieldset default input-sm form-control" style="display:' + helpers.default_filter_display(options) + ';" type="' + options.field_type + '" name="' + options.value_name + '[]" value="' + (options.field_value[0] || '') + '" /> ' +
'<input placeholder="-∞" class="additional-fieldset between input-sm form-control" style="display:' + helpers.between_operator_display(options) + ';" type="' + options.field_type + '" name="' + options.value_name + '[]" value="' + (options.field_value[1] || '') + '" /> ' +
'<input placeholder="∞" class="additional-fieldset between input-sm form-control" style="display:' + helpers.between_operator_display(options) + ';" type="' + options.field_type + '" name="' + options.value_name + '[]" value="' + (options.field_value[2] || '') + '" />';
return component;
};

components.integer_filter_component = function (options) {
return this.number_filter_component(options);
};

components.decimal_filter_component = function (options) {
return this.number_filter_component(options);
};

components.float_filter_component = function (options) {
return this.number_filter_component(options);
};

}(FilterBoxComponents));
@@ -0,0 +1,11 @@
(function(components){

var shared_elements = components.shared_elements;
var helpers = components.helpers;

shared_elements.between_and_default_options = function (options) {
return '<option ' + helpers.default_operator_selected(options) + ' data-additional-fieldset="default" value="default">' + RailsAdmin.I18n.t("number") + '</option>' +
'<option ' + helpers.between_operator_selected(options) + ' data-additional-fieldset="between" value="between">' + RailsAdmin.I18n.t("between_and_") + '</option>';
}

}(FilterBoxComponents));
@@ -0,0 +1,25 @@

(function (components) {
var helpers = components.helpers;

components.string_filter_component = function (options) {
var control;
var component = {};
component.control = '<select class="switch-additionnal-fieldsets input-sm form-control" value="' + options.field_operator + '" name="' + options.operator_name + '">' +
'<option data-additional-fieldset="additional-fieldset"' + helpers.like_operator_selected(options) + ' value="like">' + RailsAdmin.I18n.t("contains") + '</option>' +
'<option data-additional-fieldset="additional-fieldset"' + helpers.is_operator_selected(options) + ' value="is">' + RailsAdmin.I18n.t("is_exactly") + '</option>' +
'<option data-additional-fieldset="additional-fieldset"' + helpers.starts_with_operstor_selected(options) + ' value="starts_with">' + RailsAdmin.I18n.t("starts_with") + '</option>' +
'<option data-additional-fieldset="additional-fieldset"' + helpers.ends_with_operator_selected(options) + ' value="ends_with">' + RailsAdmin.I18n.t("ends_with") + '</option>' +
'<option disabled="disabled">---------</option>' +
'<option ' + helpers.not_null_operator_selected(options) + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
'<option ' + helpers.null_operator_selected(options) + ' value="_null">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
'</select>';
component.additional_control = '<input class="additional-fieldset input-sm form-control" style="display:' + (options.field_operator === "_blank" || options.field_operator === "_present" ? 'none' : 'inline-block') + ';" type="text" name="' + options.value_name + '" value="' + options.field_value + '" />';
return component;
};

components.text_filter_component = function (options) {
return this.string_filter_component(options)
};

}(FilterBoxComponents));
13 changes: 13 additions & 0 deletions app/assets/javascripts/rails_admin/ra.filter-box-components.js
@@ -0,0 +1,13 @@

var FilterBoxComponents = {
helpers: {},
shared_elements: {},
create: function(options){
var fieldFactoryName = options.field_type + '_filter_component';
try {
return this[fieldFactoryName](options);
} catch (e) {
throw('FilterComponent.createError: ' + e + '. The most likely fix is to create a function in "FilterComponents" named "' + fieldFactoryName + '(options)" that returns a filter component HTML.')
}
}
};

0 comments on commit 9935d86

Please sign in to comment.