metaminded/tabulatr2

View on GitHub
app/views/tabulatr/_tabulatr_filter_dialog.html.slim

Summary

Maintainability
Test Coverage
/  Copyright (c) 2010-2014 Peter Horn & Florian Thomas, metaminded UG
/
/  Permission is hereby granted, free of charge, to any person obtaining
/  a copy of this software and associated documentation files (the
/  "Software"), to deal in the Software without restriction, including
/  without limitation the rights to use, copy, modify, merge, publish,
/  distribute, sublicense, and/or sell copies of the Software, and to
/  permit persons to whom the Software is furnished to do so, subject to
/  the following conditions:
/
/  The above copyright notice and this permission notice shall be
/  included in all copies or substantial portions of the Software.
/
/  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
/  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
/  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
/  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
/  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
/  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


.tabulatr-filter-popover title="Filter" data-table=table_id
  form.form.tabulatr_filter_form data-table=table_id  data-remote="true" role='form'
    .panel.panel-default
      .panel-heading
        = t('tabulatr.filter')
        .btn-group.pull-right
          a.tabulatr-reset-table.btn.btn-danger.btn-xs data-tabulatr-reset=table_id
            = fa_icon :remove
          a.tabulatr-submit-table.btn.btn-primary.btn-xs
            = fa_icon 'arrow-right'
      .panel-body
        .wech style='text-indent: -2000px; height: 0px'
          = submit_tag "Anwenden"
        input name="#{formatted_name}_sort" type="hidden" value=table_options[:order_by]
        - if table_options[:filter] && columns.select(&:filter).present?
          - columns.select(&:filter).each do |column|
            - name = column.full_name
            .row.tabulatr-filter-row
              .col-xs-12
                .control-group.form-group data-filter-column-name=name
                  - iname = "#{formatted_name}_filter[#{name}]"
                  - filter_name = "tabulatr_form_#{name}"

                  label.control-label for=filter_name
                    = column.col_options.filter_label || column.human_name

                  - if column.filter.is_a?(Hash) || column.filter.is_a?(Array) || column.filter.is_a?(String)
                    select.form-control.no-chosen id=name name=iname
                      - if column.filter.class.is_a?(String)
                        = column.filter
                      - else
                        option
                        = options_for_select(column.filter)
                  - elsif column.filter == :range
                    .col-sm-5
                      input.tabulatr_filter.form-control type="text" id="#{name}_from" data-tabulatr-attribute="#{name}_from" name="#{iname}[from]"
                    span.col-sm-1.text-center —
                    .col-sm-5
                      input.tabulatr_filter.form-control type="text" id="#{name}_to" data-tabulatr-attribute="#{name}_to" name="#{iname}[to]"
                  - elsif column.filter == :checkbox
                    .col-xs-12
                      = select_tag(iname, options_for_select([ \
                          [t('tabulatr.boolean_filter.both'), ""],
                          [t('tabulatr.boolean_filter.no'), "false"],
                          [t('tabulatr.boolean_filter.yes'), "true"]] \
                        ), class: 'form-control no-chosen')
                  - elsif [:exact, :integer, :decimal].member? column.filter
                    input.tabulatr_filter.form-control type="text" id="#{name}_exact" data-tabulatr-attribute="#{name}" name="#{iname}"
                  - elsif column.filter == :date
                    select.form-control.no-chosen name="#{iname}[date][simple]" data-tabulatr-date-filter="#{formatted_name}_#{name}_filter"
                      option= I18n.t("tabulatr.date_filter.none")
                      option value="today"= I18n.t("tabulatr.date_filter.today")
                      option value="yesterday"= I18n.t("tabulatr.date_filter.yesterday")
                      option value="this_week"= I18n.t("tabulatr.date_filter.this_week")
                      option value="last_7_days"= I18n.t("tabulatr.date_filter.last_7_days")
                      option value="this_month"= I18n.t("tabulatr.date_filter.this_month")
                      option value="last_30_days"= I18n.t("tabulatr.date_filter.last_30_days")
                      option value="from_to"= "#{I18n.t('tabulatr.date_filter.from')} - #{I18n.t('tabulatr.date_filter.to')}"
                    .row.from_to.hidden
                      .col-xs-6
                        .control-group
                          label.control-label for="#{formatted_name}_#{name}_filter_from"
                            = I18n.t("tabulatr.date_filter.from")
                          input.tabulatr_filter.form-control.date-picker.hidden.from_to type="text" id="#{formatted_name}_#{name}_filter_from" name="#{iname}[date][from]"
                      .col-xs-6
                        .control-group
                          label.control-label for="#{formatted_name}_#{name}_filter_from"
                            = I18n.t("tabulatr.date_filter.to")
                          input.tabulatr_filter.form-control.date-picker.from_to.hidden type="text" id="#{formatted_name}_#{name}_filter_to" name="#{iname}[date][to]"
                  - elsif column.filter == :enum
                    select.form-control name=iname data-tabulatr-attribute=name
                      option= I18n.t('tabulatr.enum_filter.none')
                      - column.klass.try(column.name.to_s.pluralize.to_sym).each do |key, value|
                        option value=value = key
                  - elsif column.filter == :enum_multiselect
                    - column.klass.try(column.name.to_s.pluralize.to_sym).each do |key, value|
                      .row
                        .col-xs-2
                          = check_box_tag "#{iname}[]", value, true, {id: "check_box_#{key}"}
                        .col-xs-10
                          = label_tag "check_box_#{key}", key
                  - else
                    input.tabulatr_filter.form-control type="text" data-tabulatr-attribute="#{name}" name="#{iname}[like]"
        - filter.each do |f|
          .row.tabulatr-filter-row
            .col-xs-12
              = render f.to_partial_path, {input_name: "#{formatted_name}_filter[#{f.name}]",
                                            input_id: "#{formatted_name}_#{f.name}"}