fat_free_crm 0.18.2 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fat_free_crm might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +61 -160
- data/.travis.yml +27 -11
- data/CHANGELOG.md +40 -24
- data/CONTRIBUTORS.md +1 -0
- data/Dockerfile +45 -14
- data/Gemfile +16 -10
- data/Gemfile.lock +230 -222
- data/Procfile +1 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/app/assets/stylesheets/common.scss +1 -1
- data/app/controllers/admin/application_controller.rb +1 -1
- data/app/controllers/admin/field_groups_controller.rb +1 -3
- data/app/controllers/admin/tags_controller.rb +1 -3
- data/app/controllers/admin/users_controller.rb +5 -8
- data/app/controllers/application_controller.rb +11 -45
- data/app/controllers/comments_controller.rb +2 -5
- data/{config/initializers/authlogic.rb → app/controllers/confirmations_controller.rb} +4 -2
- data/app/controllers/emails_controller.rb +0 -2
- data/app/controllers/entities/accounts_controller.rb +1 -3
- data/app/controllers/entities/campaigns_controller.rb +1 -3
- data/app/controllers/entities/contacts_controller.rb +4 -24
- data/app/controllers/entities/leads_controller.rb +7 -10
- data/app/controllers/entities/opportunities_controller.rb +4 -14
- data/app/controllers/entities_controller.rb +21 -7
- data/app/controllers/home_controller.rb +2 -4
- data/app/controllers/passwords_controller.rb +3 -59
- data/{spec/features/support/maintain_sessions.rb → app/controllers/registrations_controller.rb} +12 -5
- data/{lib/development_tasks/gem.rake → app/controllers/sessions_controller.rb} +6 -6
- data/app/controllers/tasks_controller.rb +8 -17
- data/app/controllers/users_controller.rb +8 -29
- data/app/helpers/admin/users_helper.rb +1 -1
- data/app/helpers/application_helper.rb +27 -32
- data/app/helpers/campaigns_helper.rb +1 -1
- data/app/helpers/contacts_helper.rb +1 -3
- data/app/helpers/opportunities_helper.rb +4 -12
- data/app/helpers/tasks_helper.rb +1 -1
- data/app/helpers/users_helper.rb +1 -3
- data/{config/initializers/paper_trail.rb → app/mailers/devise_mailer.rb} +5 -1
- data/app/mailers/user_mailer.rb +0 -9
- data/app/models/entities/account.rb +10 -10
- data/app/models/entities/campaign.rb +4 -6
- data/app/models/entities/contact.rb +24 -12
- data/app/models/entities/lead.rb +7 -7
- data/app/models/entities/opportunity.rb +7 -9
- data/app/models/fields/custom_field.rb +1 -0
- data/app/models/fields/custom_field_date_pair.rb +2 -0
- data/app/models/fields/field.rb +1 -3
- data/app/models/list.rb +1 -1
- data/app/models/observers/entity_observer.rb +3 -7
- data/app/models/observers/lead_observer.rb +2 -4
- data/app/models/observers/opportunity_observer.rb +2 -4
- data/app/models/observers/task_observer.rb +1 -1
- data/app/models/polymorphic/email.rb +2 -2
- data/app/models/polymorphic/task.rb +13 -9
- data/app/models/polymorphic/version.rb +3 -2
- data/app/models/setting.rb +2 -0
- data/app/models/users/permission.rb +3 -3
- data/app/models/users/preference.rb +2 -1
- data/app/models/users/user.rb +67 -42
- data/app/views/accounts/_top_section.html.haml +1 -1
- data/app/views/accounts/edit.js.haml +1 -1
- data/app/views/accounts/update.js.haml +2 -2
- data/app/views/admin/users/_user.html.haml +4 -4
- data/app/views/contacts/_index_brief.html.haml +1 -1
- data/app/views/contacts/_index_full.html.haml +1 -1
- data/app/views/contacts/_index_long.html.haml +1 -1
- data/app/views/devise/confirmations/new.html.haml +9 -0
- data/app/views/devise/mailer/confirmation_instructions.html.haml +4 -0
- data/app/views/devise/mailer/password_change.html.haml +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.haml +6 -0
- data/app/views/devise/passwords/edit.html.haml +18 -0
- data/app/views/devise/passwords/new.html.haml +10 -0
- data/app/views/devise/registrations/new.html.haml +21 -0
- data/app/views/devise/sessions/new.html.haml +32 -0
- data/app/views/layouts/_about.html.haml +5 -5
- data/app/views/layouts/_header.html.haml +3 -3
- data/app/views/layouts/admin/_header.html.haml +1 -1
- data/app/views/shared/_address.html.haml +5 -5
- data/app/views/shared/_paginate_with_per_page.html.haml +1 -0
- data/app/views/users/_avatar.html.haml +1 -1
- data/bin/bundle +1 -1
- data/bin/rails +1 -1
- data/bin/setup +38 -0
- data/bin/update +33 -0
- data/bin/yarn +13 -0
- data/config/application.rb +8 -6
- data/config/boot.rb +1 -1
- data/config/brakeman.ignore +2 -2
- data/config/database.postgres.docker.yml +5 -5
- data/config/environment.rb +1 -1
- data/config/environments/development.rb +1 -0
- data/config/environments/test.rb +7 -0
- data/config/initializers/action_mailer.rb +1 -3
- data/config/initializers/application_controller_renderer.rb +9 -0
- data/config/initializers/assets.rb +6 -11
- data/config/initializers/backtrace_silencers.rb +0 -6
- data/config/initializers/content_security_policy.rb +26 -0
- data/config/initializers/cookies_serializer.rb +3 -6
- data/config/initializers/devise.rb +289 -0
- data/config/initializers/filter_parameter_logging.rb +0 -5
- data/config/initializers/gravatar.rb +0 -1
- data/config/initializers/inflections.rb +0 -6
- data/config/initializers/mime_types.rb +1 -9
- data/config/initializers/new_framework_defaults_5_2.rb +40 -0
- data/config/initializers/relative_url_root.rb +1 -3
- data/config/initializers/session_store.rb +1 -3
- data/config/initializers/wrap_parameters.rb +4 -9
- data/config/locales/fat_free_crm.en-GB.yml +5 -5
- data/config/locales/fat_free_crm.en-US.yml +5 -5
- data/config/locales/fat_free_crm.fr.yml +1 -1
- data/config/locales/fat_free_crm.ru.yml +1 -0
- data/config/routes.rb +20 -9
- data/db/demo/users.yml +62 -81
- data/db/migrate/20100928030620_remove_uuid.rb +1 -2
- data/db/migrate/20120316045804_activities_to_versions.rb +1 -0
- data/db/migrate/20120510025219_add_not_null_constraints_for_timestamp_columns.rb +1 -0
- data/db/migrate/20180107082701_authlogic_to_devise.rb +58 -0
- data/db/schema.rb +48 -43
- data/docker-compose.yml +10 -0
- data/fat_free_crm.gemspec +11 -13
- data/lib/development_tasks/license.rake +2 -2
- data/lib/fat_free_crm/callback.rb +2 -2
- data/lib/fat_free_crm/comment_extensions.rb +2 -4
- data/lib/fat_free_crm/core_ext/string.rb +1 -1
- data/lib/fat_free_crm/engine.rb +1 -1
- data/lib/fat_free_crm/errors.rb +1 -1
- data/lib/fat_free_crm/export_csv.rb +1 -0
- data/lib/fat_free_crm/exportable.rb +1 -1
- data/lib/fat_free_crm/fields.rb +1 -1
- data/lib/fat_free_crm/gem_dependencies.rb +1 -1
- data/lib/fat_free_crm/gem_ext/simple_form/action_view_extensions/form_helper.rb +1 -3
- data/lib/fat_free_crm/i18n.rb +2 -2
- data/lib/fat_free_crm/mail_processor/base.rb +4 -10
- data/lib/fat_free_crm/mail_processor/dropbox.rb +5 -15
- data/lib/fat_free_crm/permissions.rb +7 -4
- data/lib/fat_free_crm/sortable.rb +1 -1
- data/lib/fat_free_crm/tabs.rb +2 -2
- data/lib/fat_free_crm/version.rb +2 -2
- data/lib/gravatar_image_tag.rb +7 -8
- data/lib/missing_translation_detector.rb +1 -0
- data/lib/tasks/ffcrm/missing_translations.rake +1 -0
- data/lib/tasks/ffcrm/setup.rake +10 -1
- data/lib/tasks/ffcrm/update_data.rake +2 -2
- data/script/rails +2 -2
- data/spec/controllers/admin/users_controller_spec.rb +0 -56
- data/spec/controllers/comments_controller_spec.rb +6 -6
- data/spec/controllers/entities/campaigns_controller_spec.rb +1 -1
- data/spec/controllers/entities/contacts_controller_spec.rb +2 -1
- data/spec/controllers/entities/leads_controller_spec.rb +2 -2
- data/spec/controllers/entities/opportunities_controller_spec.rb +1 -1
- data/spec/controllers/entities_controller_spec.rb +5 -0
- data/spec/controllers/home_controller_spec.rb +5 -5
- data/spec/controllers/tasks_controller_spec.rb +6 -4
- data/spec/controllers/users_controller_spec.rb +28 -98
- data/spec/factories/account_factories.rb +5 -5
- data/spec/factories/campaign_factories.rb +3 -3
- data/spec/factories/contact_factories.rb +8 -8
- data/spec/factories/field_factories.rb +4 -3
- data/spec/factories/lead_factories.rb +5 -5
- data/spec/factories/list_factories.rb +2 -2
- data/spec/factories/opportunity_factories.rb +3 -3
- data/spec/factories/setting_factories.rb +2 -2
- data/spec/factories/shared_factories.rb +11 -9
- data/spec/factories/task_factories.rb +7 -7
- data/spec/factories/user_factories.rb +16 -19
- data/spec/features/admin/groups_spec.rb +1 -1
- data/spec/features/admin/users_spec.rb +3 -1
- data/spec/features/campaigns_spec.rb +1 -1
- data/spec/features/contacts_spec.rb +1 -1
- data/spec/features/dashboard_spec.rb +1 -1
- data/spec/features/devise/sign_in_spec.rb +58 -0
- data/spec/features/devise/sign_up_spec.rb +36 -0
- data/spec/features/leads_spec.rb +1 -1
- data/spec/features/opportunities_overview_spec.rb +1 -1
- data/spec/features/opportunities_spec.rb +3 -3
- data/spec/features/support/browser.rb +2 -1
- data/spec/features/tasks_spec.rb +1 -1
- data/spec/helpers/admin/field_groups_helper_spec.rb +1 -1
- data/spec/helpers/users_helper_spec.rb +4 -4
- data/spec/lib/comment_extensions_spec.rb +10 -4
- data/spec/lib/errors_spec.rb +2 -2
- data/spec/lib/mail_processor/dropbox_spec.rb +1 -1
- data/spec/lib/mail_processor/sample_emails/dropbox.rb +8 -8
- data/spec/lib/permissions_spec.rb +8 -3
- data/spec/mailers/devise_mailer_spec.rb +35 -0
- data/spec/mailers/user_mailer_spec.rb +0 -26
- data/spec/models/entities/account_spec.rb +27 -0
- data/spec/models/entities/contact_spec.rb +96 -1
- data/spec/models/fields/custom_field_date_pair_spec.rb +4 -2
- data/spec/models/fields/custom_field_spec.rb +4 -2
- data/spec/models/observers/entity_observer_spec.rb +1 -1
- data/spec/models/polymorphic/version_spec.rb +7 -7
- data/spec/models/users/user_spec.rb +22 -26
- data/spec/routing/users_routing_spec.rb +30 -8
- data/spec/shared/controllers.rb +3 -9
- data/spec/spec_helper.rb +10 -2
- data/spec/support/assert_select.rb +1 -0
- data/spec/support/devise_helpers.rb +28 -0
- data/spec/{features/support/helpers.rb → support/feature_helpers.rb} +10 -10
- data/spec/support/macros.rb +4 -1
- data/spec/views/contacts/update.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/update.js.haml_spec.rb +1 -1
- data/vendor/gems/ransack_ui-1.3.4/.gitignore +17 -0
- data/vendor/gems/ransack_ui-1.3.4/Gemfile +7 -0
- data/vendor/gems/ransack_ui-1.3.4/LICENSE.txt +22 -0
- data/vendor/gems/ransack_ui-1.3.4/README.md +57 -0
- data/vendor/gems/ransack_ui-1.3.4/Rakefile +1 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/images/ransack_ui/calendar.png +0 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/images/ransack_ui/delete.png +0 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/javascripts/ransack/predicates.js.coffee +41 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/javascripts/ransack_ui_bootstrap/button_group_select.js.coffee +26 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/javascripts/ransack_ui_bootstrap/index.js.coffee +2 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/javascripts/ransack_ui_jquery/index.js +2 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/javascripts/ransack_ui_jquery/search_form.js.coffee.erb +499 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/stylesheets/ransack_ui_bootstrap/index.css +3 -0
- data/vendor/gems/ransack_ui-1.3.4/app/assets/stylesheets/ransack_ui_bootstrap/search.css.scss +41 -0
- data/vendor/gems/ransack_ui-1.3.4/app/views/ransack_ui/_condition_fields.html.erb +15 -0
- data/vendor/gems/ransack_ui-1.3.4/app/views/ransack_ui/_grouping_fields.html.erb +16 -0
- data/vendor/gems/ransack_ui-1.3.4/app/views/ransack_ui/_search.html.erb +29 -0
- data/vendor/gems/ransack_ui-1.3.4/app/views/ransack_ui/_sort_fields.html.erb +4 -0
- data/vendor/gems/ransack_ui-1.3.4/config/locales/en.yml +24 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui.rb +9 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/adapters/active_record.rb +6 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/adapters/active_record/base.rb +46 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/controller_helpers.rb +18 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/rails/engine.rb +21 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/adapters/active_record/base.rb +47 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/configuration.rb +15 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/context.rb +9 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/helpers/form_builder.rb +262 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/nodes/attribute.rb +13 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/nodes/condition.rb +13 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/ransack_overrides/nodes/grouping.rb +20 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/version.rb +3 -0
- data/vendor/gems/ransack_ui-1.3.4/lib/ransack_ui/view_helpers.rb +30 -0
- data/vendor/gems/ransack_ui-1.3.4/ransack_ui.gemspec +23 -0
- metadata +79 -67
- data/app/controllers/authentications_controller.rb +0 -53
- data/app/models/users/authentication.rb +0 -56
- data/app/views/authentications/new.html.haml +0 -19
- data/app/views/passwords/edit.html.haml +0 -15
- data/app/views/passwords/new.html.haml +0 -10
- data/app/views/user_mailer/password_reset_instructions.html.haml +0 -6
- data/app/views/users/new.html.haml +0 -19
- data/spec/controllers/authentications_controller_spec.rb +0 -150
- data/spec/controllers/passwords_controller_spec.rb +0 -32
- data/spec/models/users/authentication_spec.rb +0 -19
- data/spec/support/auth_macros.rb +0 -49
- data/spec/views/authentications/new.haml_spec.rb +0 -31
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Converts a select list into a bootstrap button-group with radio button behaviour
|
3
|
+
#
|
4
|
+
(($) ->
|
5
|
+
$.widget 'ransack.button_group_select',
|
6
|
+
options: {}
|
7
|
+
|
8
|
+
_create: ->
|
9
|
+
el = @element
|
10
|
+
val = el.val()
|
11
|
+
el.hide()
|
12
|
+
|
13
|
+
html = '<div class="btn-group btn-group-select" data-toggle="buttons-radio">'
|
14
|
+
el.find('option').each (i, o) ->
|
15
|
+
html += "<button class=\"btn#{if o.value == val then ' active' else ''}\" type=\"button\" value=\"#{o.value}\">#{o.text}</button>"
|
16
|
+
|
17
|
+
# Insert HTML after hidden select
|
18
|
+
el.after html
|
19
|
+
|
20
|
+
# Update select val when button is clicked
|
21
|
+
btn_group = el.next()
|
22
|
+
btn_group.on 'click', 'button.btn', (e) =>
|
23
|
+
@element.val $(e.currentTarget).val()
|
24
|
+
true
|
25
|
+
|
26
|
+
) jQuery
|
data/vendor/gems/ransack_ui-1.3.4/app/assets/javascripts/ransack_ui_jquery/search_form.js.coffee.erb
ADDED
@@ -0,0 +1,499 @@
|
|
1
|
+
(($) ->
|
2
|
+
$.widget 'ransack.ransack_search_form',
|
3
|
+
options: {}
|
4
|
+
|
5
|
+
_create: ->
|
6
|
+
el = @element
|
7
|
+
el.on 'click', '.add_fields', $.proxy(@add_fields, this)
|
8
|
+
el.on 'click', '.remove_fields', $.proxy(@remove_fields, this)
|
9
|
+
el.on 'change', 'select.ransack_predicate', $.proxy(@predicate_changed, this)
|
10
|
+
el.on 'change', 'select.ransack_attribute', $.proxy(@attribute_changed, this)
|
11
|
+
el.on 'change', 'input.ransack_query_multi', $.proxy(@multi_query_changed, this)
|
12
|
+
|
13
|
+
# Store initial predicates and set up Select2 on select lists in .filters
|
14
|
+
containers = el.find('.filters')
|
15
|
+
if Select2?
|
16
|
+
@init_select2(containers)
|
17
|
+
@store_initial_predicates(containers)
|
18
|
+
|
19
|
+
if $.ransack.button_group_select?
|
20
|
+
@init_button_group_select(@element)
|
21
|
+
|
22
|
+
# show spinner and disable the form when the search is underway
|
23
|
+
el.find("form input:submit").click $.proxy(@form_submit, this)
|
24
|
+
|
25
|
+
# Fire change event for any existing attribute selects,
|
26
|
+
# set initialize to true so that existing queries are not cleared.
|
27
|
+
el.find(".filters select.ransack_attribute").each (i, el) =>
|
28
|
+
@attribute_changed({currentTarget: el}, true)
|
29
|
+
|
30
|
+
attribute_changed: (e, initialize = false) ->
|
31
|
+
target = $(e.currentTarget)
|
32
|
+
selected_attribute = target.find('option:selected')
|
33
|
+
column_type = selected_attribute.data('type')
|
34
|
+
|
35
|
+
base_id = target.attr('id').slice(0, -8)
|
36
|
+
predicate_select = @element.find("select##{base_id}p")
|
37
|
+
available = predicate_select.data['predicates']
|
38
|
+
query_input = $("input##{base_id}v_0_value")
|
39
|
+
multi_id = query_input.attr('id') + '_multi'
|
40
|
+
multi_input = @element.find("##{multi_id}")
|
41
|
+
query_select2_id = "#s2id_#{base_id}v_0_value"
|
42
|
+
query_select2 = @element.find(query_select2_id)
|
43
|
+
predicate_select2_id = "#s2id_#{base_id}p"
|
44
|
+
predicate_select2 = @element.find(predicate_select2_id)
|
45
|
+
|
46
|
+
# Initialize datepicker if column is date/datetime/time
|
47
|
+
$.proxy(@init_datetimepicker, this)(base_id)
|
48
|
+
|
49
|
+
# Clear input value unless this is the first run
|
50
|
+
unless initialize
|
51
|
+
query_input.val('')
|
52
|
+
|
53
|
+
# Destroy any query select2 inputs on attribute change and clear input
|
54
|
+
if query_select2.length
|
55
|
+
query_input.select2('destroy')
|
56
|
+
|
57
|
+
# Destroy any multi-inputs on attribute change and clear input
|
58
|
+
if multi_input.length
|
59
|
+
@destroy_multi_input(multi_input, selected_attribute.val())
|
60
|
+
|
61
|
+
# Handle association columns with AJAX autocomplete
|
62
|
+
if selected_attribute.data('ajax-url') and Select2?
|
63
|
+
@set_option_predicates(base_id, available, column_type)
|
64
|
+
|
65
|
+
# Handle columns with options detected from validates :inclusion
|
66
|
+
else if selected_attribute.data('select-options') and Select2?
|
67
|
+
@set_option_predicates(base_id, available, column_type, true)
|
68
|
+
|
69
|
+
# Handle regular columns
|
70
|
+
else
|
71
|
+
if Select2?
|
72
|
+
predicate_select2.select2("enable")
|
73
|
+
|
74
|
+
# If Select2 is on query input, remove and set defaults
|
75
|
+
if query_select2.length > 0
|
76
|
+
query_input.select2('destroy')
|
77
|
+
query_input.val('')
|
78
|
+
previous_val = ''
|
79
|
+
else
|
80
|
+
previous_val = predicate_select.val()
|
81
|
+
|
82
|
+
# Build array of supported predicates
|
83
|
+
predicates = Ransack.type_predicates[column_type] || []
|
84
|
+
predicates = $.map predicates, (p) -> [p, Ransack.predicates[p]]
|
85
|
+
|
86
|
+
# Remove all predicates, and add any supported predicates
|
87
|
+
predicate_select.find('option').each (i, o) -> $(o).remove()
|
88
|
+
|
89
|
+
$.each available, (i, p) =>
|
90
|
+
[predicate, label] = [p[0], p[1]]
|
91
|
+
|
92
|
+
# Also allow compound predicates, unless column
|
93
|
+
# is a date type. (No support for any/all on dates yet.)
|
94
|
+
if !column_type?.match(/date|time/)
|
95
|
+
p_key = predicate.replace(/_(any|all)$/, '')
|
96
|
+
else
|
97
|
+
p_key = predicate
|
98
|
+
|
99
|
+
if p_key in predicates
|
100
|
+
# Get alternative predicate label depending on column type
|
101
|
+
label = @alt_predicate_label_or_default(predicate, column_type, label)
|
102
|
+
predicate_select.append $("<option value=#{predicate}>#{label}</option>")
|
103
|
+
|
104
|
+
# Select first predicate if current selection is invalid
|
105
|
+
if Select2?
|
106
|
+
predicate_select.select2('val', previous_val)
|
107
|
+
|
108
|
+
# Run predicate_changed callback
|
109
|
+
predicate_select.change()
|
110
|
+
|
111
|
+
return true
|
112
|
+
|
113
|
+
|
114
|
+
predicate_changed: (e) ->
|
115
|
+
target = $(e.currentTarget)
|
116
|
+
p = target.val() || ""
|
117
|
+
base_id = target.attr('id').slice(0, -1)
|
118
|
+
query_input = $("input##{base_id}v_0_value")
|
119
|
+
|
120
|
+
attribute_select = @element.find("select##{base_id}a_0_name")
|
121
|
+
selected_attribute = attribute_select.find('option:selected')
|
122
|
+
|
123
|
+
query_select2_id = "#s2id_#{base_id}v_0_value"
|
124
|
+
query_select2 = @element.find(query_select2_id)
|
125
|
+
query_select2_multi_id = "#s2id_#{base_id}v_0_value_multi"
|
126
|
+
query_select2_multi = @element.find(query_select2_multi_id)
|
127
|
+
|
128
|
+
no_query_predicates = ["true", "false", "blank", "present", "null", "not_null"]
|
129
|
+
|
130
|
+
# We need to use a dummy input to handle multiple terms
|
131
|
+
multi_id = query_input.attr('id') + '_multi'
|
132
|
+
multi_input = @element.find("##{multi_id}")
|
133
|
+
|
134
|
+
# If query was previously hidden, clear query input
|
135
|
+
if query_select2.length == 0 && multi_input.length == 0 && query_input.is(":hidden")
|
136
|
+
query_input.val('')
|
137
|
+
|
138
|
+
# Hide query input when not needed
|
139
|
+
if p in no_query_predicates
|
140
|
+
# If Select2 is on query input, remove and set defaults
|
141
|
+
if Select2? && query_select2.length
|
142
|
+
query_input.select2('destroy')
|
143
|
+
|
144
|
+
query_input.val("true")
|
145
|
+
query_input.hide()
|
146
|
+
query_input.parent().find('.ui-datepicker-trigger').hide()
|
147
|
+
|
148
|
+
if Select2?
|
149
|
+
# Turn query input into Select2 tag list when query accepts multiple values
|
150
|
+
if p in ["in", "not_in"] || p.match(/_(all|any)$/)
|
151
|
+
# Add dummy 'multi' input for select2 if not already added
|
152
|
+
if multi_input.length == 0 && query_select2_multi.length == 0
|
153
|
+
# Set up multi-query input with fixed options, if present
|
154
|
+
@setup_multi_query_input(target, query_input, multi_id, selected_attribute)
|
155
|
+
|
156
|
+
# If Select2 is on query input, remove and set defaults
|
157
|
+
if query_select2.length
|
158
|
+
query_input.select2('destroy').hide()
|
159
|
+
|
160
|
+
return
|
161
|
+
|
162
|
+
else
|
163
|
+
# Otherwise, remove Select2 from multi-query input, and remove input.
|
164
|
+
if multi_input.length
|
165
|
+
# Save label data from first value
|
166
|
+
if multi_input.select2('data') && multi_input.select2('data').length
|
167
|
+
multi_input_data = multi_input.select2('data').first()
|
168
|
+
Ransack.value_field_labels[selected_attribute.val()] ||= {}
|
169
|
+
Ransack.value_field_labels[selected_attribute.val()][multi_input_data.id] = multi_input_data.text
|
170
|
+
|
171
|
+
@destroy_multi_input(multi_input, selected_attribute.val())
|
172
|
+
|
173
|
+
if p not in no_query_predicates
|
174
|
+
#query_input.show()
|
175
|
+
query_input.css('display', '')
|
176
|
+
|
177
|
+
# Handle association columns with AJAX autocomplete
|
178
|
+
if selected_attribute.data('ajax-url')
|
179
|
+
if query_select2.length
|
180
|
+
query_input.hide()
|
181
|
+
else
|
182
|
+
@setup_select2_association(query_input, selected_attribute)
|
183
|
+
|
184
|
+
# Handle fixed options - set up Select2 for single values if not already present
|
185
|
+
if selected_attribute.data('select-options')
|
186
|
+
if query_select2.length
|
187
|
+
query_input.hide()
|
188
|
+
else
|
189
|
+
@setup_select2_options(query_input, selected_attribute)
|
190
|
+
|
191
|
+
# Otherwise, reset query input and show datepicker trigger if present
|
192
|
+
if p not in no_query_predicates
|
193
|
+
return if selected_attribute.data('select-options')
|
194
|
+
|
195
|
+
# Don't show query input if ajax auto complete is present on selected attribute
|
196
|
+
unless p in ['eq', 'not_eq'] and selected_attribute.data('ajax-url')
|
197
|
+
unless query_input.is(":visible")
|
198
|
+
query_input.val('')
|
199
|
+
#query_input.show()
|
200
|
+
query_input.css('display', '')
|
201
|
+
query_input.parent().find('.ui-datepicker-trigger').show()
|
202
|
+
|
203
|
+
|
204
|
+
# Disables predicate choices and sets it to 'eq'
|
205
|
+
set_option_predicates: (base_id, available_predicates, column_type, include_number_predicates = false) ->
|
206
|
+
predicate_select = @element.find("select##{base_id}p")
|
207
|
+
previous_val = predicate_select.val()
|
208
|
+
|
209
|
+
# Remove all predicates, and add any supported predicates
|
210
|
+
predicate_select.find('option').each (i, o) -> $(o).remove()
|
211
|
+
|
212
|
+
allowed_predicates = $.merge([], Ransack.option_predicates)
|
213
|
+
|
214
|
+
# Include number predicates if the option was given.
|
215
|
+
# For example, a integer column will have fixed select options,
|
216
|
+
# but will also allow less than and greater than.
|
217
|
+
if column_type in ['integer', 'float', 'decimal'] && include_number_predicates
|
218
|
+
allowed_predicates = allowed_predicates.concat(Ransack.type_predicates[column_type] || [])
|
219
|
+
|
220
|
+
$.each available_predicates, (i, p) =>
|
221
|
+
[predicate, label] = [p[0], p[1]]
|
222
|
+
|
223
|
+
if predicate in allowed_predicates
|
224
|
+
# Get alternative predicate label depending on column type
|
225
|
+
label = @alt_predicate_label_or_default(predicate, column_type, label)
|
226
|
+
predicate_select.append $("<option value=#{predicate}>#{label}</option>")
|
227
|
+
|
228
|
+
# Select first predicate if current selection is invalid
|
229
|
+
predicate_select.select2('val', previous_val)
|
230
|
+
|
231
|
+
# Attempts to find a predicate translation for the specific column type,
|
232
|
+
# or returns the default label.
|
233
|
+
# For example, 'lt' on an integer column will be translated to 'is less than',
|
234
|
+
# while a date column will have it translated as 'is before'.
|
235
|
+
# This is mainly to avoid confusion when building conditions using Chronic strings.
|
236
|
+
# 'created_at is less than 2 weeks ago' is misleading, and
|
237
|
+
# 'created_at is before 2 weeks ago' is much easier to understand.
|
238
|
+
alt_predicate_label_or_default: (p, type, default_label) ->
|
239
|
+
return default_label unless Ransack?.alt_predicates_i18n?
|
240
|
+
alt_labels = {}
|
241
|
+
switch type
|
242
|
+
when "date", "datetime", "time"
|
243
|
+
alt_labels = Ransack.alt_predicates_i18n["date"] || {}
|
244
|
+
else
|
245
|
+
alt_labels = Ransack.alt_predicates_i18n[type] || {}
|
246
|
+
|
247
|
+
alt_labels[p] || default_label
|
248
|
+
|
249
|
+
multi_query_changed: (e) ->
|
250
|
+
target = $(e.currentTarget)
|
251
|
+
|
252
|
+
# Fetch all query inputs for condition
|
253
|
+
base_name = target.data('base-name')
|
254
|
+
inputs = @element.find("input[name^=\"#{base_name}\"]")
|
255
|
+
|
256
|
+
# Set the original query input to the first value before shifting inputs and values
|
257
|
+
$(inputs[0]).val(e.val[0])
|
258
|
+
|
259
|
+
inputs = inputs.slice(1)
|
260
|
+
values = e.val.slice(1)
|
261
|
+
|
262
|
+
# If value was added after the first value, then append extra input with added value
|
263
|
+
if values.length && e.added
|
264
|
+
@add_query_input(target, base_name, inputs.length + 1, e.added.id)
|
265
|
+
|
266
|
+
else if e.removed
|
267
|
+
# If value was removed, clear all extra inputs, then rebuild inputs for extra terms
|
268
|
+
inputs.remove()
|
269
|
+
$.each values, (i, v) =>
|
270
|
+
@add_query_input(target, base_name, i + 1, v)
|
271
|
+
|
272
|
+
setup_multi_query_input: (predicate_el, query_input, multi_id, selected_attribute) ->
|
273
|
+
base_name = predicate_el.attr('name').slice(0, -3) + '[v]'
|
274
|
+
base_id = predicate_el.attr('id').slice(0, -1)
|
275
|
+
width = query_input.width() * 2
|
276
|
+
width = 200 if width < 10
|
277
|
+
query_input.after(
|
278
|
+
$('<input class="ransack_query_multi" id="' + multi_id + '" ' +
|
279
|
+
'style="width:' + width + 'px;" ' +
|
280
|
+
'data-base-name="' + base_name + '" />'))
|
281
|
+
|
282
|
+
query_select2_id = "#s2id_#{base_id}v_0_value"
|
283
|
+
query_select2 = @element.find(query_select2_id)
|
284
|
+
|
285
|
+
# Fetch all existing values
|
286
|
+
inputs = @element.find("input[name^=\"#{base_name}\"]")
|
287
|
+
values = $.map inputs, (el) -> el.value
|
288
|
+
# Hide all query inputs
|
289
|
+
inputs.hide()
|
290
|
+
|
291
|
+
if Select2?
|
292
|
+
# Find newly created input and setup Select2
|
293
|
+
multi_query = @element.find('#' + multi_id)
|
294
|
+
|
295
|
+
# Handle association columns with AJAX autocomplete
|
296
|
+
if selected_attribute.data('ajax-url')
|
297
|
+
# Set label to single association label, if anything was selected
|
298
|
+
if query_select2.length && query_input.select2('data')
|
299
|
+
query_input_data = query_input.select2('data')
|
300
|
+
Ransack.value_field_labels[selected_attribute.val()] ||= {}
|
301
|
+
Ransack.value_field_labels[selected_attribute.val()][query_input_data.id] = query_input_data.text
|
302
|
+
|
303
|
+
@setup_select2_association(multi_query, selected_attribute, true)
|
304
|
+
|
305
|
+
else
|
306
|
+
if selected_attribute.data('select-options')
|
307
|
+
# Setup Select2 with fixed multiple options
|
308
|
+
@setup_select2_options(multi_query, selected_attribute, true)
|
309
|
+
|
310
|
+
else
|
311
|
+
# Setup Select2 with tagging support (can create options)
|
312
|
+
multi_query.select2
|
313
|
+
tags: []
|
314
|
+
tokenSeparators: [',']
|
315
|
+
formatNoMatches: (t) ->
|
316
|
+
"Add a search term"
|
317
|
+
|
318
|
+
multi_query.select2('val', values)
|
319
|
+
|
320
|
+
setup_select2_association: (query_input, selected_attribute, multiple = false) ->
|
321
|
+
selected_attribute_val = selected_attribute.val()
|
322
|
+
# Set up Select2 for query input
|
323
|
+
query_input.select2
|
324
|
+
placeholder: "Search #{selected_attribute.data('ajax-entity')}"
|
325
|
+
minimumInputLength: 1
|
326
|
+
allowClear: true
|
327
|
+
multiple: multiple
|
328
|
+
ajax:
|
329
|
+
url: selected_attribute.data('ajax-url')
|
330
|
+
dataType: 'json'
|
331
|
+
type: selected_attribute.data('ajax-type')
|
332
|
+
data: (query, page) ->
|
333
|
+
obj = {}
|
334
|
+
obj[selected_attribute.data('ajax-key')] = query
|
335
|
+
obj
|
336
|
+
results: (data, page) ->
|
337
|
+
{results: $.map(data, (text, id) -> {id: id, text: text}) }
|
338
|
+
initSelection: (element, callback) ->
|
339
|
+
data = []
|
340
|
+
unless element.val().trim() == ""
|
341
|
+
$(element.val().split(",")).each (i, val) ->
|
342
|
+
label = Ransack.value_field_labels[selected_attribute_val]?[val]
|
343
|
+
if label
|
344
|
+
data.push {id: val, text: label}
|
345
|
+
else
|
346
|
+
data.push {id: val, text: val}
|
347
|
+
if data.length
|
348
|
+
callback(multiple and data or data[0])
|
349
|
+
else
|
350
|
+
# If no label could be found, clear value
|
351
|
+
element.select2('val', '')
|
352
|
+
|
353
|
+
setup_select2_options: (query_input, selected_attribute, multiple = false) ->
|
354
|
+
query_input.select2
|
355
|
+
data: selected_attribute.data('select-options')
|
356
|
+
placeholder: "Please select a #{selected_attribute.text()}"
|
357
|
+
allowClear: true
|
358
|
+
multiple: multiple
|
359
|
+
tokenSeparators: [',']
|
360
|
+
formatNoMatches:
|
361
|
+
if selected_attribute.data('select-options')
|
362
|
+
(t) -> "No matches found."
|
363
|
+
else
|
364
|
+
(t) -> "Add a search term"
|
365
|
+
initSelection: (element, callback) ->
|
366
|
+
data = []
|
367
|
+
unless element.val().trim() == ""
|
368
|
+
$(element.val().split(",")).each (i, val) ->
|
369
|
+
selected_attribute.data('select-options').each (option, i) ->
|
370
|
+
if option.id == val
|
371
|
+
data.push {id: option.id, text: option.text}
|
372
|
+
return false # Break out of inner each loop
|
373
|
+
|
374
|
+
if data.length
|
375
|
+
callback(multiple and data or data[0])
|
376
|
+
else
|
377
|
+
element.select2('val', '')
|
378
|
+
|
379
|
+
add_query_input: (base_input, base_name, id, value) ->
|
380
|
+
base_input.after $('<input name="'+base_name+'['+id+'][value]" '+
|
381
|
+
'value="'+value+'" style="display:none;" />')
|
382
|
+
|
383
|
+
destroy_multi_input: (multi_input, selected_attribute_val) ->
|
384
|
+
multi_input.select2('destroy').remove()
|
385
|
+
# Also remove all extra inputs
|
386
|
+
base_name = multi_input.data('base-name')
|
387
|
+
inputs = @element.find("input[name^=\"#{base_name}\"]")
|
388
|
+
inputs = inputs.slice(1)
|
389
|
+
inputs.remove()
|
390
|
+
|
391
|
+
form_submit: (e) ->
|
392
|
+
@element.css({ opacity: 0.4 })
|
393
|
+
true
|
394
|
+
|
395
|
+
add_fields: (e) ->
|
396
|
+
target = $(e.currentTarget)
|
397
|
+
type = target.data("fieldType")
|
398
|
+
content = target.data("content")
|
399
|
+
new_id = new Date().getTime()
|
400
|
+
regexp = new RegExp('new_' + type, 'g')
|
401
|
+
target.before content.replace(regexp, new_id)
|
402
|
+
prev_container = target.prev()
|
403
|
+
|
404
|
+
if Select2?
|
405
|
+
@init_select2(prev_container)
|
406
|
+
|
407
|
+
if $.ransack.button_group_select?
|
408
|
+
@init_button_group_select(prev_container)
|
409
|
+
|
410
|
+
@store_initial_predicates(prev_container)
|
411
|
+
# Fire change event on any new selects.
|
412
|
+
prev_container.find("select").change()
|
413
|
+
false
|
414
|
+
|
415
|
+
remove_fields: (e) ->
|
416
|
+
target = $(e.currentTarget)
|
417
|
+
container = target.closest('.fields')
|
418
|
+
if (container.siblings().length > 1)
|
419
|
+
container.remove()
|
420
|
+
else
|
421
|
+
container.parent().closest('.fields').remove()
|
422
|
+
false
|
423
|
+
|
424
|
+
store_initial_predicates: (container) ->
|
425
|
+
# Store current predicates in data attribute
|
426
|
+
predicate_select = container.find('select.ransack_predicate').first()
|
427
|
+
unless predicate_select.data['predicates']
|
428
|
+
predicates = []
|
429
|
+
predicate_select.find('option').each (i, o) ->
|
430
|
+
o = $(o)
|
431
|
+
predicates.push [o.val(), o.text()]
|
432
|
+
predicate_select.data['predicates'] = predicates
|
433
|
+
|
434
|
+
init_select2: (container) ->
|
435
|
+
container.find('select.ransack_predicate').select2
|
436
|
+
width: '160px'
|
437
|
+
formatNoMatches: (term) ->
|
438
|
+
"Select a field first"
|
439
|
+
|
440
|
+
container.find('select.ransack_attribute').select2
|
441
|
+
width: '230px'
|
442
|
+
placeholder: "Select a Field"
|
443
|
+
allowClear: true
|
444
|
+
formatSelection: (object, container) ->
|
445
|
+
# If initializing and element is not present,
|
446
|
+
# search for option element in original select tag
|
447
|
+
if !object.element
|
448
|
+
this.element.find('option').each (i, option) ->
|
449
|
+
if option.value == object.id
|
450
|
+
object.element = option
|
451
|
+
return false
|
452
|
+
|
453
|
+
# Return 'Model: field' unless column is on root model
|
454
|
+
if $(object.element).data('root-model')
|
455
|
+
object.text
|
456
|
+
else
|
457
|
+
group_label = $(object.element).parent().attr('label')
|
458
|
+
# Avoid labels like 'Contact: Contact'
|
459
|
+
if group_label == object.text
|
460
|
+
object.text
|
461
|
+
else if group_label?
|
462
|
+
group_label + ': ' + object.text
|
463
|
+
else
|
464
|
+
object.text
|
465
|
+
|
466
|
+
@element.find('select.ransack_sort').select2
|
467
|
+
width: '230px'
|
468
|
+
placeholder: "Select a Field"
|
469
|
+
|
470
|
+
init_button_group_select: (containers) ->
|
471
|
+
containers.find('select.ransack_combinator, select.ransack_sort_order').button_group_select()
|
472
|
+
|
473
|
+
init_datetimepicker: (base_id) ->
|
474
|
+
if $.ui?.timepicker?
|
475
|
+
query_input = @element.find("input##{base_id}v_0_value")
|
476
|
+
selected_attribute = @element.find("select##{base_id}a_0_name option:selected")
|
477
|
+
|
478
|
+
# Clear any datepicker from query input first
|
479
|
+
query_input.datepicker('destroy')
|
480
|
+
|
481
|
+
datepicker_options =
|
482
|
+
changeMonth: true
|
483
|
+
constrainInput: false
|
484
|
+
dateFormat: 'yy-mm-dd'
|
485
|
+
buttonImage: "<%= asset_path('ransack_ui/calendar.png') %>"
|
486
|
+
buttonImageOnly: true
|
487
|
+
showOn: 'button'
|
488
|
+
# Always prefer custom input text over selected date
|
489
|
+
onClose: (date) -> $(this).val(date)
|
490
|
+
|
491
|
+
# Show datepicker button for dates
|
492
|
+
switch selected_attribute.data('type')
|
493
|
+
when "date"
|
494
|
+
query_input.datepicker(datepicker_options)
|
495
|
+
when "datetime"
|
496
|
+
query_input.datetimepicker(datepicker_options)
|
497
|
+
when "time"
|
498
|
+
query_input.datetimepicker $.extend(datepicker_options, {timeOnly: true})
|
499
|
+
) jQuery
|