- rtc_controller_name ||= controller_name - the_klass = instance_variable_get("@#{rtc_controller_name}").klass - search_key ||= 'q' - search_action ||= search_action - advanced_search_attributes ||= nil = simple_form_for instance_variable_get("@#{search_key}"), as: search_key.to_sym, url: search_action.presence || '#', html: {method: :get, id: "#{rtc_controller_name}_advanced_search", class: 'rtc_advanced_search form-horizontal'}, remote: true do |f| - advanced_search_attributes.compact.each do |att| - # Check attribute type, then breakdown att - case att - when Hash - att_params = att[:params] - att = att[:input] - attribute = att.to_s - range = true - if att.instance_of?(Hash) - attribute = att[:attribute].to_s - range = att[:range].presence || true - label_name = att[:label] - splitter = attribute.split('.') - attribute_name = splitter.pop - attribute_type = splitter.inject(the_klass){|memo, obj| memo.reflect_on_all_associations.find{|c| c.name.eql?(obj.to_sym)}.klass}.columns_hash[attribute_name].type - underscore_attribute = attribute.gsub('.', '_') - label_name ||= [splitter.last, attribute_name].compact.join('_') - if att_params.present? - ransack_predicate = (att_params[:ransack_predicate].presence || :eq).to_s = f.input "#{underscore_attribute}_#{ransack_predicate}".to_sym, att_params.merge!({required: false}) - else - case attribute_type - when :string = f.input "#{underscore_attribute}_cont".to_sym, label: label_name, required: false - when :text = f.input "#{underscore_attribute}_cont".to_sym, label: label_name, required: false - when :integer - if range .control-group.optional.range.integer %label.integer.optional.control-label{for: "q_#{attribute_name}_gteq"}= t(label_name) .controls %input.integer.numeric.optional{id: "q_#{attribute_name}_gteq", name: "q[#{attribute_name}_gteq]", size: "50", type: "text"} %span.floating = t('to') .controls.floating %input.integer.numeric.optional{id: "q_#{attribute_name}_lteq", name: "q[#{attribute_name}_lteq]", size: "50", type: "text"} - else = f.input "#{underscore_attribute}_eq".to_sym, label: label_name, required: false - when :float - if range .control-group.optional.range.float %label.float.optional.control-label{for: "q_#{attribute_name}_gteq"}= t(label_name) .controls %input.float.numeric.optional{id: "q_#{attribute_name}_gteq", name: "q[#{attribute_name}_gteq]", size: "50", type: "text"} %span.floating = t('to') .controls.floating %input.float.numeric.optional{id: "q_#{attribute_name}_lteq", name: "q[#{attribute_name}_lteq]", size: "50", type: "text"} - else = f.input "#{underscore_attribute}_eq".to_sym, label: label_name, required: false - when :date - if range .control-group.string.optional.range %label.string.optional.control-label{for: "q_#{attribute_name}_gteq"}= t(label_name) .controls %input.string.optional.datepicker{id: "q_#{rtc_controller_name}_#{attribute_name}_gteq", name: "q[#{attribute_name}_gteq]", size: "50", type: "text"} %p.help-block DD-MM-YYYY %span.floating = t('to') .controls.floating %input.string.optional.datepicker{id: "q_#{rtc_controller_name}_#{attribute_name}_lteq", name: "q[#{attribute_name}_lteq]", size: "50", type: "text"} %p.help-block DD-MM-YYYY - else = f.input "#{underscore_attribute}_eq".to_sym, label: label_name, required: false, input_html: { class: 'datepicker' }, hint: 'DD-MM-YYYY' - when :datetime - if range .control-group.string.optional.range %label.string.optional.control-label{for: "q_#{attribute_name}_gteq"}= t(label_name) .controls %input.string.optional.datepicker{id: "q_#{rtc_controller_name}_#{attribute_name}_gteq", name: "q[#{attribute_name}_gteq]", size: "50", type: "text"} %p.help-block DD-MM-YYYY %span.floating = t('to') .controls.floating %input.string.optional.datepicker{id: "q_#{rtc_controller_name}_#{attribute_name}_lteq", name: "q[#{attribute_name}_lteq]", size: "50", type: "text"} %p.help-block DD-MM-YYYY - else = f.input "#{rtc_controller_name}_#{underscore_attribute}_eq".to_sym, label: label_name, required: false, input_html: { class: 'datepicker' }, hint: 'DD-MM-YYYY' .form-actions %button{type: 'submit', class: 'btn btn-primary'} = icon('search', t('search')) .clear_advanced_search.btn.btn-mini = t('reset') .hide_advanced_search.btn.btn-mini = t('hide')