fat_free_crm 0.17.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 +5 -5
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +71 -148
- data/.travis.yml +35 -14
- data/CHANGELOG.md +88 -5
- data/CONTRIBUTORS.md +96 -53
- data/Dockerfile +45 -14
- data/Gemfile +23 -13
- data/Gemfile.lock +249 -241
- data/Procfile +1 -1
- data/README.md +9 -6
- data/Rakefile +1 -1
- data/app/assets/javascripts/crm.js.coffee +3 -3
- data/app/assets/javascripts/crm_select2.js.coffee +15 -14
- 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 +9 -4
- data/app/controllers/admin/fields_controller.rb +4 -4
- data/app/controllers/admin/groups_controller.rb +1 -1
- data/app/controllers/admin/tags_controller.rb +2 -4
- data/app/controllers/admin/users_controller.rb +5 -8
- data/app/controllers/application_controller.rb +22 -45
- data/app/controllers/comments_controller.rb +16 -11
- 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 +8 -5
- data/app/controllers/entities/contacts_controller.rb +4 -24
- data/app/controllers/entities/leads_controller.rb +16 -12
- data/app/controllers/entities/opportunities_controller.rb +17 -16
- data/app/controllers/entities_controller.rb +31 -12
- data/app/controllers/home_controller.rb +2 -4
- data/app/controllers/lists_controller.rb +5 -1
- 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 +22 -17
- data/app/controllers/users_controller.rb +8 -29
- data/app/helpers/accounts_helper.rb +1 -1
- data/app/helpers/admin/users_helper.rb +1 -1
- data/app/helpers/application_helper.rb +28 -33
- data/app/helpers/campaigns_helper.rb +1 -1
- data/app/helpers/contacts_helper.rb +1 -3
- data/app/helpers/leads_helper.rb +1 -1
- data/app/helpers/opportunities_helper.rb +48 -3
- data/app/helpers/tags_helper.rb +1 -1
- 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 -14
- data/app/models/entities/opportunity.rb +10 -11
- 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 +5 -7
- 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/ability.rb +3 -4
- 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/campaigns/_metrics.html.haml +3 -3
- 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/home/_opportunity.html.haml +4 -19
- 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/opportunities/_index_long.html.haml +1 -24
- data/app/views/opportunities/_sidebar_show.html.haml +3 -3
- data/app/views/opportunities/_top_section.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 -46
- data/docker-compose.yml +10 -0
- data/fat_free_crm.gemspec +12 -14
- 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 +2 -2
- 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 +2 -2
- 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 -18
- 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 +13 -4
- data/lib/tasks/ffcrm/update_data.rake +2 -2
- data/script/rails +2 -2
- data/spec/controllers/admin/users_controller_spec.rb +25 -81
- data/spec/controllers/comments_controller_spec.rb +19 -19
- data/spec/controllers/emails_controller_spec.rb +2 -2
- data/spec/controllers/entities/accounts_controller_spec.rb +56 -56
- data/spec/controllers/entities/campaigns_controller_spec.rb +66 -66
- data/spec/controllers/entities/contacts_controller_spec.rb +69 -68
- data/spec/controllers/entities/leads_controller_spec.rb +126 -126
- data/spec/controllers/entities/opportunities_controller_spec.rb +101 -101
- data/spec/controllers/entities_controller_spec.rb +5 -0
- data/spec/controllers/home_controller_spec.rb +30 -30
- data/spec/controllers/tasks_controller_spec.rb +42 -40
- data/spec/controllers/users_controller_spec.rb +43 -113
- data/spec/factories/account_factories.rb +13 -13
- data/spec/factories/campaign_factories.rb +8 -8
- data/spec/factories/contact_factories.rb +18 -18
- data/spec/factories/field_factories.rb +11 -10
- data/spec/factories/lead_factories.rb +13 -13
- data/spec/factories/list_factories.rb +3 -3
- data/spec/factories/opportunity_factories.rb +9 -9
- data/spec/factories/sequences.rb +1 -1
- data/spec/factories/setting_factories.rb +5 -5
- data/spec/factories/shared_factories.rb +25 -23
- data/spec/factories/subscription_factories.rb +1 -1
- data/spec/factories/tag_factories.rb +1 -1
- data/spec/factories/task_factories.rb +11 -11
- data/spec/factories/user_factories.rb +27 -30
- data/spec/features/accounts_spec.rb +17 -4
- data/spec/features/admin/groups_spec.rb +2 -2
- data/spec/features/admin/users_spec.rb +4 -2
- data/spec/features/campaigns_spec.rb +5 -5
- data/spec/features/contacts_spec.rb +11 -5
- data/spec/features/dashboard_spec.rb +8 -8
- 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 +5 -5
- data/spec/features/opportunities_overview_spec.rb +16 -16
- data/spec/features/opportunities_spec.rb +35 -9
- data/spec/features/support/autocomlete_helper.rb +17 -0
- data/spec/features/support/browser.rb +5 -9
- data/spec/features/tasks_spec.rb +5 -5
- data/spec/helpers/admin/field_groups_helper_spec.rb +1 -1
- data/spec/helpers/application_helper_spec.rb +1 -1
- data/spec/helpers/tasks_helper_spec.rb +1 -1
- data/spec/helpers/users_helper_spec.rb +7 -7
- data/spec/lib/comment_extensions_spec.rb +11 -5
- data/spec/lib/errors_spec.rb +2 -2
- data/spec/lib/mail_processor/base_spec.rb +3 -3
- data/spec/lib/mail_processor/comment_replies_spec.rb +3 -3
- data/spec/lib/mail_processor/dropbox_spec.rb +17 -17
- data/spec/lib/mail_processor/sample_emails/dropbox.rb +8 -8
- data/spec/lib/permissions_spec.rb +15 -28
- data/spec/mailers/devise_mailer_spec.rb +35 -0
- data/spec/mailers/user_mailer_spec.rb +6 -32
- data/spec/models/entities/account_spec.rb +58 -32
- data/spec/models/entities/campaign_spec.rb +18 -25
- data/spec/models/entities/contact_spec.rb +113 -21
- data/spec/models/entities/lead_spec.rb +9 -11
- data/spec/models/entities/opportunity_spec.rb +45 -45
- data/spec/models/fields/custom_field_date_pair_spec.rb +4 -2
- data/spec/models/fields/custom_field_spec.rb +21 -19
- data/spec/models/list_spec.rb +2 -2
- data/spec/models/observers/entity_observer_spec.rb +7 -7
- data/spec/models/polymorphic/address_spec.rb +1 -1
- data/spec/models/polymorphic/avatar_spec.rb +5 -5
- data/spec/models/polymorphic/comment_spec.rb +5 -5
- data/spec/models/polymorphic/task_spec.rb +65 -58
- data/spec/models/polymorphic/version_spec.rb +31 -31
- data/spec/models/setting_spec.rb +2 -2
- data/spec/models/users/preference_spec.rb +6 -6
- data/spec/models/users/user_spec.rb +46 -50
- data/spec/routing/users_routing_spec.rb +30 -8
- data/spec/shared/controllers.rb +3 -9
- data/spec/shared/models.rb +22 -22
- data/spec/spec_helper.rb +12 -4
- 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} +11 -11
- data/spec/support/macros.rb +7 -4
- data/spec/views/accounts/_edit.haml_spec.rb +1 -1
- data/spec/views/accounts/create.js.haml_spec.rb +2 -2
- data/spec/views/accounts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/accounts/edit.js.haml_spec.rb +2 -2
- data/spec/views/accounts/index.haml_spec.rb +2 -2
- data/spec/views/accounts/index.js.haml_spec.rb +1 -1
- data/spec/views/accounts/show.haml_spec.rb +4 -4
- data/spec/views/accounts/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/create.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/destroy.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/edit.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/new.js.haml_spec.rb +1 -1
- data/spec/views/admin/field_groups/update.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/create.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/destroy.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/edit.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/index.haml_spec.rb +1 -1
- data/spec/views/admin/users/index.js.haml_spec.rb +2 -2
- data/spec/views/admin/users/reactivate.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/suspend.js.haml_spec.rb +1 -1
- data/spec/views/admin/users/update.js.haml_spec.rb +1 -1
- data/spec/views/application/auto_complete.haml_spec.rb +3 -3
- data/spec/views/campaigns/_edit.haml_spec.rb +1 -1
- data/spec/views/campaigns/create.js.haml_spec.rb +3 -3
- data/spec/views/campaigns/destroy.js.haml_spec.rb +1 -1
- data/spec/views/campaigns/edit.js.haml_spec.rb +2 -2
- data/spec/views/campaigns/index.haml_spec.rb +1 -1
- data/spec/views/campaigns/index.js.haml_spec.rb +1 -1
- data/spec/views/campaigns/show.haml_spec.rb +4 -4
- data/spec/views/campaigns/update.js.haml_spec.rb +1 -1
- data/spec/views/contacts/_edit.haml_spec.rb +7 -7
- data/spec/views/contacts/_new.haml_spec.rb +1 -1
- data/spec/views/contacts/create.js.haml_spec.rb +4 -4
- data/spec/views/contacts/destroy.js.haml_spec.rb +1 -1
- data/spec/views/contacts/edit.js.haml_spec.rb +3 -3
- data/spec/views/contacts/index.haml_spec.rb +1 -1
- data/spec/views/contacts/index.js.html_spec.rb +1 -1
- data/spec/views/contacts/new.js.haml_spec.rb +1 -1
- data/spec/views/contacts/show.haml_spec.rb +3 -3
- data/spec/views/contacts/update.js.haml_spec.rb +3 -3
- data/spec/views/home/index.haml_spec.rb +1 -1
- data/spec/views/home/index.js.haml_spec.rb +1 -1
- data/spec/views/home/options.js.haml_spec.rb +2 -2
- data/spec/views/leads/_convert.haml_spec.rb +3 -3
- data/spec/views/leads/_edit.haml_spec.rb +2 -2
- data/spec/views/leads/_new.haml_spec.rb +2 -2
- data/spec/views/leads/_sidebar_show.haml_spec.rb +5 -5
- data/spec/views/leads/convert.js.haml_spec.rb +4 -4
- data/spec/views/leads/create.js.haml_spec.rb +5 -5
- data/spec/views/leads/destroy.js.haml_spec.rb +2 -2
- data/spec/views/leads/edit.js.haml_spec.rb +4 -4
- data/spec/views/leads/index.haml_spec.rb +1 -1
- data/spec/views/leads/index.js.haml_spec.rb +1 -1
- data/spec/views/leads/new.js.haml_spec.rb +1 -1
- data/spec/views/leads/promote.js.haml_spec.rb +7 -7
- data/spec/views/leads/reject.js.haml_spec.rb +2 -2
- data/spec/views/leads/show.haml_spec.rb +2 -2
- data/spec/views/leads/update.js.haml_spec.rb +4 -4
- data/spec/views/opportunities/_edit.haml_spec.rb +7 -7
- data/spec/views/opportunities/_new.haml_spec.rb +2 -2
- data/spec/views/opportunities/create.js.haml_spec.rb +6 -6
- data/spec/views/opportunities/destroy.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/edit.js.haml_spec.rb +3 -3
- data/spec/views/opportunities/index.haml_spec.rb +1 -1
- data/spec/views/opportunities/index.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/new.js.haml_spec.rb +1 -1
- data/spec/views/opportunities/show.haml_spec.rb +3 -3
- data/spec/views/opportunities/update.js.haml_spec.rb +5 -5
- data/spec/views/tasks/_edit.haml_spec.rb +1 -1
- data/spec/views/tasks/complete.js.haml_spec.rb +4 -4
- data/spec/views/tasks/create.js.haml_spec.rb +6 -6
- data/spec/views/tasks/destroy.js.haml_spec.rb +2 -2
- data/spec/views/tasks/index.haml_spec.rb +4 -4
- data/spec/views/tasks/new.js.haml_spec.rb +1 -1
- data/spec/views/tasks/uncomplete.js.haml_spec.rb +2 -2
- data/spec/views/tasks/update.js.haml_spec.rb +18 -18
- data/spec/views/users/upload_avatar.js.haml_spec.rb +2 -2
- 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 +83 -70
- 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
@@ -17,7 +17,7 @@ describe "/tasks/destroy" do
|
|
17
17
|
TASK_STATUSES.each do |status|
|
18
18
|
describe "destroy from Tasks tab (#{status} view)" do
|
19
19
|
before do
|
20
|
-
@task =
|
20
|
+
@task = build_stubbed(:task)
|
21
21
|
assign(:task, @task)
|
22
22
|
assign(:view, status)
|
23
23
|
assign(:empty_bucket, :due_asap)
|
@@ -46,7 +46,7 @@ describe "/tasks/destroy" do
|
|
46
46
|
|
47
47
|
describe "destroy from related asset" do
|
48
48
|
it "should blind up out destroyed task partial" do
|
49
|
-
@task =
|
49
|
+
@task = build_stubbed(:task)
|
50
50
|
assign(:task, @task)
|
51
51
|
controller.request.env["HTTP_REFERER"] = "http://localhost/leads/123"
|
52
52
|
|
@@ -16,10 +16,10 @@ describe "/tasks/index" do
|
|
16
16
|
|
17
17
|
TASK_STATUSES.each do |status|
|
18
18
|
before do
|
19
|
-
user =
|
20
|
-
account =
|
21
|
-
@due =
|
22
|
-
@completed =
|
19
|
+
user = build_stubbed(:user)
|
20
|
+
account = build_stubbed(:account)
|
21
|
+
@due = build_stubbed(:task, asset: account, bucket: "due_asap", assignee: user)
|
22
|
+
@completed = build_stubbed(:task, asset: account, bucket: "completed_today", assignee: user, completed_at: 1.hour.ago, completor: user)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should render list of #{status} tasks if list of tasks is not empty" do
|
@@ -12,7 +12,7 @@ describe "/tasks/new" do
|
|
12
12
|
|
13
13
|
before do
|
14
14
|
login
|
15
|
-
assign(:task,
|
15
|
+
assign(:task, build(:task))
|
16
16
|
assign(:users, [current_user])
|
17
17
|
assign(:bucket, Setting.task_bucket[1..-1] << ["On Specific Date...", :specific_time])
|
18
18
|
assign(:category, Setting.unroll(:task_category))
|
@@ -17,7 +17,7 @@ describe "/tasks/uncomplete" do
|
|
17
17
|
|
18
18
|
describe "uncomplete from Tasks tab (completed view)" do
|
19
19
|
before do
|
20
|
-
@task =
|
20
|
+
@task = build_stubbed(:task)
|
21
21
|
assign(:task, @task)
|
22
22
|
assign(:view, "completed")
|
23
23
|
assign(:empty_bucket, :due_asap)
|
@@ -33,7 +33,7 @@ describe "/tasks/uncomplete" do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should update tasks sidebar" do
|
36
|
-
assign(:task,
|
36
|
+
assign(:task, build_stubbed(:task))
|
37
37
|
controller.request.env["HTTP_REFERER"] = "http://localhost/tasks"
|
38
38
|
|
39
39
|
render
|
@@ -16,8 +16,8 @@ describe "/tasks/update" do
|
|
16
16
|
|
17
17
|
describe "Changing due date" do
|
18
18
|
before do
|
19
|
-
assign(:task_before_update,
|
20
|
-
assign(:task, @task =
|
19
|
+
assign(:task_before_update, build_stubbed(:task, bucket: "due_asap"))
|
20
|
+
assign(:task, @task = build_stubbed(:task, bucket: "due_tomorrow"))
|
21
21
|
assign(:view, "pending")
|
22
22
|
assign(:task_total, stub_task_total("pending"))
|
23
23
|
end
|
@@ -64,9 +64,9 @@ describe "/tasks/update" do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "pending task to somebody from Tasks tab: should remove the task and show flash message (assigned)" do
|
67
|
-
assignee =
|
68
|
-
assign(:task_before_update,
|
69
|
-
assign(:task, @task =
|
67
|
+
assignee = build_stubbed(:user)
|
68
|
+
assign(:task_before_update, build_stubbed(:task, assignee: nil))
|
69
|
+
assign(:task, @task = build_stubbed(:task, assignee: assignee))
|
70
70
|
assign(:view, "pending")
|
71
71
|
controller.request.env["HTTP_REFERER"] = "http://localhost/tasks"
|
72
72
|
|
@@ -78,9 +78,9 @@ describe "/tasks/update" do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it "assigned tasks to me from Tasks tab: should remove the task and show flash message (pending)" do
|
81
|
-
assignee =
|
82
|
-
assign(:task_before_update,
|
83
|
-
assign(:task, @task =
|
81
|
+
assignee = build_stubbed(:user)
|
82
|
+
assign(:task_before_update, build_stubbed(:task, assignee: assignee))
|
83
|
+
assign(:task, @task = build_stubbed(:task, assignee: nil))
|
84
84
|
assign(:view, "assigned")
|
85
85
|
controller.request.env["HTTP_REFERER"] = "http://localhost/tasks?view=assigned"
|
86
86
|
|
@@ -92,8 +92,8 @@ describe "/tasks/update" do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it "assigned tasks to somebody else from Tasks tab: should re-render task partial" do
|
95
|
-
assign(:task_before_update,
|
96
|
-
assign(:task, @task =
|
95
|
+
assign(:task_before_update, build_stubbed(:task, assignee: build_stubbed(:user)))
|
96
|
+
assign(:task, @task = build_stubbed(:task, assignee: build_stubbed(:user)))
|
97
97
|
assign(:view, "assigned")
|
98
98
|
controller.request.env["HTTP_REFERER"] = "http://localhost/tasks?view=assigned"
|
99
99
|
|
@@ -102,8 +102,8 @@ describe "/tasks/update" do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it "from Tasks tab: should update tasks sidebar" do
|
105
|
-
assign(:task_before_update,
|
106
|
-
assign(:task, @task =
|
105
|
+
assign(:task_before_update, build_stubbed(:task, assignee: nil))
|
106
|
+
assign(:task, @task = build_stubbed(:task, assignee: build_stubbed(:user)))
|
107
107
|
assign(:view, "assigned")
|
108
108
|
controller.request.env["HTTP_REFERER"] = "http://localhost/tasks?view=assigned"
|
109
109
|
render
|
@@ -115,16 +115,16 @@ describe "/tasks/update" do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
it "from asset page: should should re-render task partial" do
|
118
|
-
assign(:task_before_update,
|
119
|
-
assign(:task, @task =
|
118
|
+
assign(:task_before_update, build_stubbed(:task, assignee: nil))
|
119
|
+
assign(:task, @task = build_stubbed(:task, assignee: build_stubbed(:user)))
|
120
120
|
render
|
121
121
|
|
122
122
|
expect(rendered).to include("$('#task_#{@task.id}').html('<li class=\\'highlight task\\' id=\\'task_#{@task.id}\\'")
|
123
123
|
end
|
124
124
|
|
125
125
|
it "from asset page: should update recently viewed items" do
|
126
|
-
assign(:task_before_update,
|
127
|
-
assign(:task, @task =
|
126
|
+
assign(:task_before_update, build_stubbed(:task, assignee: nil))
|
127
|
+
assign(:task, @task = build_stubbed(:task, assignee: build_stubbed(:user)))
|
128
128
|
render
|
129
129
|
|
130
130
|
expect(rendered).to have_text("Recent Items")
|
@@ -132,8 +132,8 @@ describe "/tasks/update" do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "error: should re-disiplay [Edit Task] form and shake it" do
|
135
|
-
assign(:task_before_update,
|
136
|
-
assign(:task, @task =
|
135
|
+
assign(:task_before_update, build_stubbed(:task))
|
136
|
+
assign(:task, @task = build_stubbed(:task))
|
137
137
|
@task.errors.add(:name)
|
138
138
|
|
139
139
|
render
|
@@ -16,7 +16,7 @@ describe "/users/upload_avatar" do
|
|
16
16
|
|
17
17
|
describe "no errors:" do
|
18
18
|
before do
|
19
|
-
@avatar =
|
19
|
+
@avatar = build_stubbed(:avatar, entity: current_user)
|
20
20
|
allow(current_user).to receive(:avatar).and_return(@avatar)
|
21
21
|
assign(:user, @user = current_user)
|
22
22
|
end
|
@@ -31,7 +31,7 @@ describe "/users/upload_avatar" do
|
|
31
31
|
|
32
32
|
describe "validation errors:" do
|
33
33
|
before do
|
34
|
-
@avatar =
|
34
|
+
@avatar = build_stubbed(:avatar, entity: current_user)
|
35
35
|
@avatar.errors.add(:image, "error")
|
36
36
|
allow_any_instance_of(User).to receive(:avatar).and_return(@avatar)
|
37
37
|
assign(:user, @user = current_user)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nathan Broadbent
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Ransack UI
|
2
|
+
|
3
|
+
Provides HTML templates and JavaScript to build a fully functional
|
4
|
+
advanced search form using Ransack.
|
5
|
+
|
6
|
+
Please note: this project is still in *alpha* and the following instructions are not yet complete/fully working.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'ransack_ui'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install ransack_ui
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Make your model ransackable (if you name associations, it will enable you to search them aswell).
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
has_ransackable_associations %w(account tags)
|
28
|
+
ransack_can_autocomplete
|
29
|
+
```
|
30
|
+
|
31
|
+
In your controller, where you'd like to add search functionality, add the following before_filter hook. You can change the 'index' action if needed.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
before_filter :load_ransack_search, :only => :index
|
35
|
+
```
|
36
|
+
|
37
|
+
Insert the following helper call into your rails view code where you'd like the search form to appear.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
= ransack_ui_search
|
41
|
+
```
|
42
|
+
|
43
|
+
Now you can start playing with the results.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
52
|
+
|
53
|
+
## Credits / Acknowledgements
|
54
|
+
|
55
|
+
* Nathan Broadbent (ndbroadbent) - creator of ransack_ui code
|
56
|
+
* Ernie Miller (ernie) for creating ransack - https://github.com/ernie/ransack
|
57
|
+
* Steve Kenworthy (steveyken) - for tiny tweaks
|
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
window.Ransack ?= {}
|
2
|
+
|
3
|
+
Ransack.predicates =
|
4
|
+
eq: 'not_eq'
|
5
|
+
cont: 'not_cont'
|
6
|
+
matches: 'does_not_match'
|
7
|
+
start: 'not_start'
|
8
|
+
end: 'not_end'
|
9
|
+
present: 'blank'
|
10
|
+
null: 'not_null'
|
11
|
+
lt: 'gteq'
|
12
|
+
gt: 'lteq'
|
13
|
+
in: 'not_in'
|
14
|
+
true: 'false'
|
15
|
+
|
16
|
+
# Setup supported predicates for each column type.
|
17
|
+
Ransack.type_predicates = {}
|
18
|
+
((o, f) -> f.call o) Ransack.type_predicates, ->
|
19
|
+
@text = @string = ['eq', 'cont', 'matches', 'start', 'end', 'present', 'in']
|
20
|
+
@boolean = ['true', 'null']
|
21
|
+
@integer = @float = @decimal = ['eq', 'null', 'lt', 'gt', 'in']
|
22
|
+
@date = @datetime = @time = ['eq', 'null', 'lt', 'gt']
|
23
|
+
|
24
|
+
# Setup input field types for each predicate
|
25
|
+
Ransack.predicate_inputs = {}
|
26
|
+
((o, f) -> f.call o) Ransack.predicate_inputs, ->
|
27
|
+
@cont = @matches = @start = @end = @in = 'string'
|
28
|
+
@present = @null = @true = false
|
29
|
+
@eq = @gt = @lt = (type) ->
|
30
|
+
switch type
|
31
|
+
when 'string','text' then 'string'
|
32
|
+
when 'integer','float','decimal' then 'numeric'
|
33
|
+
when 'date','datetime','time' then type
|
34
|
+
else false # Hide for unhandled types.
|
35
|
+
|
36
|
+
# Setup predicates for fixed select options. Includes relevant any/all permutations
|
37
|
+
Ransack.option_predicates = ['eq', 'eq_any', 'not_eq', 'not_eq_all', 'null', 'not_null']
|
38
|
+
|
39
|
+
# Use a tags input for 'in' if Select2 is available
|
40
|
+
if Select2?
|
41
|
+
Ransack.predicate_inputs.in = 'tags'
|
@@ -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
|