brisk-bills 0.7.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +55 -0
- data/TODO.txt +36 -67
- data/app/controllers/admin/activities_controller.rb +4 -3
- data/app/controllers/admin/activities_with_prices_controller.rb +28 -14
- data/app/controllers/admin/client_accounting_controller.rb +11 -8
- data/app/controllers/admin/client_representatives_controller.rb +34 -5
- data/app/controllers/admin/clients_controller.rb +1 -1
- data/app/controllers/admin/draft_invoices_controller.rb +92 -0
- data/app/controllers/admin/{employee_client_labor_rate_controller.rb → employee_client_labor_rates_controller.rb} +1 -1
- data/app/controllers/admin/employees_controller.rb +3 -4
- data/app/controllers/admin/invoices_controller.rb +111 -53
- data/app/controllers/admin/payments_controller.rb +168 -41
- data/app/controllers/authentication_controller.rb +3 -3
- data/app/helpers/admin/activities_helper.rb +16 -13
- data/app/helpers/admin/activities_helper/labor_helper.rb +4 -4
- data/app/helpers/admin/activities_helper/proposal_helper.rb +1 -1
- data/app/helpers/admin/activities_helper/slimtimer_helper.rb +1 -1
- data/app/helpers/admin/activities_with_prices_helper.rb +2 -2
- data/app/helpers/admin/activity_type_controller_helper.rb +6 -0
- data/app/helpers/admin/activity_type_field_helper.rb +9 -9
- data/app/helpers/admin/adjustments_helper.rb +9 -1
- data/app/helpers/admin/client_accounting_helper.rb +2 -2
- data/app/helpers/admin/client_financial_transactions_helper.rb +1 -1
- data/app/helpers/admin/client_representatives_helper.rb +16 -12
- data/app/helpers/admin/clients_helper.rb +2 -0
- data/app/helpers/admin/draft_invoices_helper.rb +24 -0
- data/app/helpers/admin/{employee_client_labor_rate_helper.rb → employee_client_labor_rates_helper.rb} +8 -8
- data/app/helpers/admin/employees_helper.rb +6 -0
- data/app/helpers/admin/has_credential_column_helper.rb +8 -8
- data/app/helpers/admin/invoices_helper.rb +71 -16
- data/app/helpers/admin/is_active_column_helper.rb +2 -2
- data/app/helpers/admin/labors_helper.rb +12 -1
- data/app/helpers/admin/labors_helper/slimtimer_helper.rb +1 -1
- data/app/helpers/admin/materials_helper.rb +11 -0
- data/app/helpers/admin/payments_helper.rb +204 -29
- data/app/helpers/admin/proposals_helper.rb +10 -0
- data/app/helpers/admin/settings_helper.rb +1 -1
- data/app/helpers/admin_layout_helper.rb +3 -6
- data/app/helpers/authentication_helper.rb +7 -10
- data/app/helpers/money_model_helper.rb +1 -2
- data/app/models/activity.rb +17 -7
- data/app/models/client.rb +35 -8
- data/app/{model_views → models}/client_financial_transaction.rb +0 -0
- data/app/models/client_representative.rb +6 -14
- data/app/models/credential.rb +1 -1
- data/app/models/employee.rb +9 -11
- data/app/models/invoice.rb +13 -9
- data/app/models/invoice_payment.rb +1 -1
- data/app/models/notifier.rb +2 -2
- data/app/models/payment.rb +51 -7
- data/app/models/setting.rb +3 -1
- data/app/views/active_scaffold_overrides/add_existing.js.rjs +25 -0
- data/app/views/admin/activities/_adjustment_column.html.erb +10 -0
- data/app/views/admin/activities/{_form.rhtml → _form.html.erb} +0 -0
- data/app/views/admin/activities/{_form_attribute.rhtml → _form_attribute.html.erb} +0 -0
- data/app/views/admin/activities/{_labor_column.rhtml → _labor_column.html.erb} +0 -0
- data/app/views/admin/activities/{_material_column.rhtml → _material_column.html.erb} +0 -0
- data/app/views/admin/activities/{_proposal_column.rhtml → _proposal_column.html.erb} +0 -0
- data/app/views/admin/activities_with_prices/{move_to_invoice.rhtml → move_to_invoice.html.erb} +2 -2
- data/app/views/admin/activities_with_prices/move_to_invoice.js.rjs +5 -0
- data/app/views/admin/draft_invoices/batch_create.html.erb +73 -0
- data/app/views/admin/draft_invoices/batch_create.js.rjs +5 -0
- data/app/views/admin/invoices/confirm_publish_modal.html.erb +48 -0
- data/app/views/admin/payments/commit_payment_warning.html.erb +8 -0
- data/app/views/admin/payments/observation_error.js.rjs +28 -0
- data/app/views/admin/payments/on_assignment_observation.js.rjs +28 -0
- data/app/views/authentication/{email.rjs → email.js.rjs} +0 -0
- data/app/views/authentication/{login.rhtml → login.html.erb} +21 -26
- data/app/views/authentication/{login.rjs → login.js.rjs} +0 -0
- data/app/views/authentication/{reset_password_via_token.rhtml → reset_password_via_token.html.erb} +0 -0
- data/app/views/authentication/{reset_password_via_token.rjs → reset_password_via_token.js.rjs} +0 -0
- data/app/views/authentication/{sign_in_error.rjs → sign_in_error.js.rjs} +0 -0
- data/app/views/layouts/{_navigation_tree.rhtml → _navigation_tree.html.erb} +0 -0
- data/app/views/layouts/{admin.rhtml → admin.html.erb} +0 -0
- data/app/views/layouts/{public.rhtml → public.html.erb} +0 -0
- data/app/views/notifier/{_email_footer.html.rhtml → _email_footer.html.erb} +0 -0
- data/app/views/notifier/{_email_footer.plain.rhtml → _email_footer.plain.erb} +0 -0
- data/app/views/notifier/{_email_header.html.rhtml → _email_header.html.erb} +0 -0
- data/app/views/notifier/invoice_available.html.erb +5 -0
- data/app/views/notifier/{invoice_available.plain.rhtml → invoice_available.plain.erb} +1 -1
- data/app/views/notifier/{reset_password_requested.html.rhtml → reset_password_requested.html.erb} +2 -2
- data/app/views/notifier/{reset_password_requested.plain.rhtml → reset_password_requested.plain.erb} +1 -1
- data/config/environment.rb +6 -5
- data/config/locale/en.rb +9 -0
- data/db/migrate/001_create_employees.rb +1 -1
- data/db/migrate/002_create_employee_slimtimers.rb +1 -1
- data/db/migrate/003_create_slimtimer_tasks.rb +1 -1
- data/db/migrate/004_create_slimtimer_time_entries.rb +1 -1
- data/db/migrate/005_create_clients.rb +1 -1
- data/db/migrate/006_create_client_representatives.rb +1 -1
- data/db/migrate/008_create_activities.rb +1 -1
- data/db/migrate/009_create_activity_labors.rb +1 -1
- data/db/migrate/010_create_employee_client_labor_rates.rb +1 -1
- data/db/migrate/011_create_activity_adjustments.rb +1 -1
- data/db/migrate/012_create_activity_materials.rb +1 -1
- data/db/migrate/013_create_activity_proposals.rb +1 -1
- data/db/migrate/014_create_invoices.rb +1 -1
- data/db/migrate/015_create_payments.rb +1 -1
- data/db/migrate/016_create_payment_methods.rb +1 -1
- data/db/migrate/017_create_invoice_payments.rb +1 -1
- data/db/migrate/018_create_activity_types.rb +2 -2
- data/db/migrate/019_create_settings.rb +1 -1
- data/db/migrate/023_create_credentials_migrate_representatives.rb +2 -2
- data/db/migrate/028_money_to_cents.rb +2 -2
- data/db/schema.rb +10 -10
- data/lib/brisk-bills.rb +2 -2
- data/lib/brisk-bills/initializer.rb +2 -2
- data/lib/generators/instance/templates/instance_environment.rb +1 -1
- data/lib/libpptable.rb +48 -0
- data/lib/tasks/create_last_months_invoices.rake +1 -14
- data/lib/tasks/first_time_setup.rake +2 -2
- data/lib/tasks/package.rake +2 -1
- data/lib/tasks/payment_assignment_consistency_check.rake +110 -0
- data/lib/utilities.rb +4 -4
- data/public/images/page-new.gif +0 -0
- data/public/javascripts/active_scaffold/default/active_scaffold.js +532 -430
- data/public/javascripts/active_scaffold/default/dhtml_history.js +1 -1
- data/public/javascripts/active_scaffold/default/form_enhancements.js +7 -4
- data/public/stylesheets/active_scaffold/default/stylesheet-ie.css +5 -5
- data/public/stylesheets/active_scaffold/default/stylesheet.css +54 -18
- data/public/stylesheets/admin/global.css +1 -1
- data/public/stylesheets/admin/pages.css +29 -0
- data/test/unit/activity/adjustment_test.rb +1 -1
- data/test/unit/activity/labor_test.rb +1 -1
- data/test/unit/activity/material_test.rb +1 -1
- data/test/unit/activity/proposal_test.rb +1 -1
- data/test/unit/activity_test.rb +1 -1
- data/test/unit/activity_type_test.rb +1 -1
- data/test/unit/client_eventlog_test.rb +1 -1
- data/test/unit/client_financial_transaction_test.rb +1 -1
- data/test/unit/client_representative_test.rb +1 -1
- data/test/unit/client_test.rb +37 -6
- data/test/unit/credential_test.rb +1 -1
- data/test/unit/employee/slimtimer_test.rb +1 -1
- data/test/unit/employee_client_labor_rate_test.rb +1 -1
- data/test/unit/employee_test.rb +1 -1
- data/test/unit/helpers/admin/draft_invoices_helper_test.rb +4 -0
- data/test/unit/invoice_payment_test.rb +90 -50
- data/test/unit/invoice_test.rb +48 -8
- data/test/unit/notifier_test.rb +1 -1
- data/test/unit/payment_method_test.rb +1 -1
- data/test/unit/payment_test.rb +7 -7
- data/test/unit/setting_test.rb +1 -1
- data/test/unit/slimtimer_task_test.rb +1 -1
- data/test/unit/slimtimer_time_entry_test.rb +1 -1
- data/vendor/plugins/active_scaffold/CHANGELOG +3 -1
- data/vendor/plugins/active_scaffold/README +18 -5
- data/vendor/plugins/active_scaffold/environment.rb +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js +532 -430
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/dhtml_history.js +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/form_enhancements.js +7 -4
- data/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet-ie.css +5 -5
- data/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet.css +54 -18
- data/vendor/plugins/active_scaffold/frontends/default/views/_add_existing_form.html.erb +3 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_create_form.html.erb +10 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_field_search.html.erb +7 -12
- data/vendor/plugins/active_scaffold/frontends/default/views/_form.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association.html.erb +15 -20
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association_footer.html.erb +8 -10
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb +5 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_hidden_attribute.html.erb +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform.html.erb +19 -21
- data/vendor/plugins/active_scaffold/frontends/default/views/{_form_association_header.html.erb → _horizontal_subform_header.html.erb} +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform_record.html.erb +31 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list.html.erb +4 -18
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_actions.html.erb +18 -5
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_calculations.html.erb +2 -9
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_column_headings.html.erb +4 -4
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_header.html.erb +6 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_inline_adapter.html.erb +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_messages.html.erb +20 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_pagination.html.erb +11 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_pagination_links.html.erb +3 -5
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_record.html.erb +2 -26
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_record_columns.html.erb +9 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_nested.html.erb +3 -12
- data/vendor/plugins/active_scaffold/frontends/default/views/_render_fields.js.rjs +11 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_search.html.erb +17 -11
- data/vendor/plugins/active_scaffold/frontends/default/views/_show.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_show_columns.html.erb +8 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_update_actions.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_update_form.html.erb +9 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/_vertical_subform.html.erb +7 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/add_existing.js.rjs +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/delete.html.erb +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/destroy.js.rjs +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/edit_associated.js.rjs +20 -15
- data/vendor/plugins/active_scaffold/frontends/default/views/list.html.erb +12 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/list.js.rjs +1 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/mark.js.rjs +6 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/on_create.js.rjs +12 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/on_update.js.rjs +13 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/render_field.js.rjs +1 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/search.html.erb +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/update.html.erb +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/update_column.js.rjs +4 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/update_row.js.rjs +2 -0
- data/vendor/plugins/active_scaffold/init.rb +2 -2
- data/vendor/plugins/active_scaffold/install.rb +1 -2
- data/vendor/plugins/active_scaffold/install_assets.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/active_record_permissions.rb +53 -42
- data/vendor/plugins/active_scaffold/lib/active_scaffold.rb +96 -23
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/common_search.rb +18 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/core.rb +152 -102
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/create.rb +81 -49
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/delete.rb +44 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/field_search.rb +60 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/list.rb +42 -37
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/mark.rb +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/nested.rb +94 -92
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/search.rb +54 -40
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/show.rb +30 -10
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/update.rb +62 -47
- data/vendor/plugins/active_scaffold/lib/active_scaffold/attribute_params.rb +187 -185
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/base.rb +28 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb +43 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/create.rb +8 -15
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/delete.rb +3 -4
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/field_search.rb +19 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/form.rb +2 -9
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/list.rb +46 -9
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/nested.rb +17 -7
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/search.rb +36 -16
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/show.rb +5 -12
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/subform.rb +8 -6
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/update.rb +12 -8
- data/vendor/plugins/active_scaffold/lib/active_scaffold/configurable.rb +2 -2
- data/vendor/plugins/active_scaffold/lib/active_scaffold/constraints.rb +173 -178
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_columns.rb +101 -97
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_link.rb +29 -19
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb +74 -34
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb +74 -74
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb +57 -62
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/sorting.rb +73 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/finder.rb +304 -234
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/association_helpers.rb +40 -40
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb +39 -24
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/country_helpers.rb +32 -28
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/form_column_helpers.rb +157 -86
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/id_helpers.rb +7 -7
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/list_column_helpers.rb +278 -85
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/pagination_helpers.rb +38 -12
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb +74 -35
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/show_column_helpers.rb +53 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/view_helpers.rb +51 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/de.yml +69 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/en.yml +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/es.yml +23 -13
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/fr.yml +68 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/hu.yml +24 -14
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/ja.yml +69 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/ru.yml +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/marked_model.rb +38 -0
- data/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb +47 -13
- data/vendor/plugins/active_scaffold/lib/bridges/dependent_protect/bridge.rb +10 -0
- data/vendor/plugins/active_scaffold/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb +11 -0
- data/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb +3 -6
- data/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/form_ui.rb +10 -2
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/bridge.rb +13 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/form_ui.rb +20 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/list_ui.rb +16 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge.rb +32 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb +18 -0
- data/vendor/plugins/active_scaffold/lib/bridges/record_select/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/record_select/lib/record_select_bridge.rb +79 -0
- data/vendor/plugins/active_scaffold/lib/bridges/semantic_attributes/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/vendor/plugins/active_scaffold/lib/bridges/tiny_mce/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +57 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/bridge.rb +9 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb +14 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb +15 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb +16 -0
- data/vendor/plugins/active_scaffold/lib/bridges/validation_reflection/bridge.rb +9 -0
- data/vendor/plugins/active_scaffold/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb +19 -0
- data/vendor/plugins/active_scaffold/lib/extensions/action_view_rendering.rb +20 -8
- data/vendor/plugins/active_scaffold/lib/extensions/generic_view_paths.rb +2 -2
- data/vendor/plugins/active_scaffold/lib/extensions/paginator_extensions.rb +26 -0
- data/vendor/plugins/active_scaffold/lib/extensions/resources.rb +6 -5
- data/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb +26 -20
- data/vendor/plugins/active_scaffold/lib/extensions/unsaved_associated.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/paginator.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/responds_to_parent.rb +1 -1
- data/vendor/plugins/active_scaffold/shoulda_macros/macros.rb +136 -0
- data/vendor/plugins/active_scaffold/test/bridges/active_scaffold_dependent_protect_test.rb +34 -0
- data/vendor/plugins/active_scaffold/test/bridges/bridge_test.rb +43 -0
- data/vendor/plugins/active_scaffold/test/bridges/company.rb +81 -0
- data/vendor/plugins/active_scaffold/test/bridges/paperclip_test.rb +68 -0
- data/vendor/plugins/active_scaffold/test/bridges/tiny_mce_test.rb +27 -0
- data/vendor/plugins/active_scaffold/test/bridges/unobtrusive_date_picker_test.rb +49 -0
- data/vendor/plugins/active_scaffold/test/bridges/validation_reflection_test.rb +57 -0
- data/vendor/plugins/active_scaffold/test/config/base_test.rb +15 -0
- data/vendor/plugins/active_scaffold/test/config/core_test.rb +58 -0
- data/vendor/plugins/active_scaffold/test/config/create_test.rb +9 -6
- data/vendor/plugins/active_scaffold/test/config/delete_test.rb +33 -0
- data/vendor/plugins/active_scaffold/test/config/field_search_test.rb +47 -0
- data/vendor/plugins/active_scaffold/test/config/list_test.rb +66 -11
- data/vendor/plugins/active_scaffold/test/config/nested_test.rb +62 -0
- data/vendor/plugins/active_scaffold/test/config/search_test.rb +60 -0
- data/vendor/plugins/active_scaffold/test/config/show_test.rb +43 -0
- data/vendor/plugins/active_scaffold/test/config/subform_test.rb +17 -0
- data/vendor/plugins/active_scaffold/test/config/update_test.rb +27 -4
- data/vendor/plugins/active_scaffold/test/data_structures/action_columns_test.rb +2 -8
- data/vendor/plugins/active_scaffold/test/data_structures/action_link_test.rb +11 -11
- data/vendor/plugins/active_scaffold/test/data_structures/action_links_test.rb +5 -5
- data/vendor/plugins/active_scaffold/test/data_structures/association_column_test.rb +4 -3
- data/vendor/plugins/active_scaffold/test/data_structures/column_test.rb +29 -5
- data/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb +31 -1
- data/vendor/plugins/active_scaffold/test/data_structures/standard_column_test.rb +3 -13
- data/vendor/plugins/active_scaffold/test/data_structures/virtual_column_test.rb +0 -11
- data/vendor/plugins/active_scaffold/test/extensions/{array.rb → array_test.rb} +0 -0
- data/vendor/plugins/active_scaffold/test/helpers/form_column_helpers_test.rb +31 -0
- data/vendor/plugins/active_scaffold/test/helpers/list_column_helpers_test.rb +42 -0
- data/vendor/plugins/active_scaffold/test/helpers/pagination_helpers_test.rb +59 -0
- data/vendor/plugins/active_scaffold/test/misc/active_record_permissions_test.rb +154 -0
- data/vendor/plugins/active_scaffold/test/misc/attribute_params_test.rb +146 -0
- data/vendor/plugins/active_scaffold/test/misc/configurable_test.rb +2 -2
- data/vendor/plugins/active_scaffold/test/misc/constraints_test.rb +26 -8
- data/vendor/plugins/active_scaffold/test/misc/finder_test.rb +41 -19
- data/vendor/plugins/active_scaffold/test/misc/lang_test.rb +5 -6
- data/vendor/plugins/active_scaffold/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/vendor/plugins/active_scaffold/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/boot.rb +110 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environment.rb +43 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/development.rb +17 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/production.rb +28 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/test.rb +28 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/inflections.rb +10 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/session_store.rb +15 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/locales/en.yml +5 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/routes.rb +43 -0
- data/vendor/plugins/active_scaffold/test/mock_app/db/test.sqlite3 +1 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/blank.html +33 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +845 -0
- data/vendor/plugins/active_scaffold/test/model_stub.rb +17 -1
- data/vendor/plugins/active_scaffold/test/test_helper.rb +31 -5
- data/vendor/plugins/active_scaffold/uninstall.rb +2 -1
- data/vendor/plugins/active_scaffold_form_observation/init.rb +1 -1
- data/vendor/plugins/active_scaffold_form_observation/lib/active_scaffold_form_observation.rb +1 -2
- data/vendor/plugins/active_scaffold_full_refresh/init.rb +2 -0
- data/vendor/plugins/active_scaffold_full_refresh/lib/active_scaffold_full_refresh.rb +29 -0
- data/vendor/plugins/acts_as_money/{tasks → lib/tasks}/money_tasks.rake +0 -0
- metadata +668 -563
- data/app/model_views/client_accounting.rb +0 -5
- data/app/model_views/invoices_with_total.rb +0 -41
- data/app/views/admin/activities/_adjustment_column.rhtml +0 -23
- data/app/views/admin/activities_with_prices/move_to_invoice.rjs +0 -9
- data/app/views/notifier/invoice_available.html.rhtml +0 -5
- data/public/javascripts/prototype.js-1.6.0.3 +0 -4320
- data/test/functional/admin/activities_controller_test.rb +0 -8
- data/test/functional/admin/adjustments_controller_test.rb +0 -8
- data/test/functional/admin/client_accounting_controller_test.rb +0 -8
- data/test/functional/admin/client_financial_transactions_controller_test.rb +0 -8
- data/test/functional/admin/client_representatives_controller_test.rb +0 -8
- data/test/functional/admin/clients_controller_test.rb +0 -8
- data/test/functional/admin/employee_client_labor_rate_controller_test.rb +0 -8
- data/test/functional/admin/employees/slimtimer_controller_test.rb +0 -8
- data/test/functional/admin/employees_controller_test.rb +0 -8
- data/test/functional/admin/invoices_controller_test.rb +0 -8
- data/test/functional/admin/labors_controller_test.rb +0 -8
- data/test/functional/admin/materials_controller_test.rb +0 -8
- data/test/functional/admin/payments_controller_test.rb +0 -8
- data/test/functional/admin/proposals_controller_test.rb +0 -8
- data/test/functional/admin/settings_controller_test.rb +0 -8
- data/test/functional/authentication_controller_test.rb +0 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association_record.html.erb +0 -27
- data/vendor/plugins/active_scaffold/frontends/default/views/_live_search.html.erb +0 -25
- data/vendor/plugins/active_scaffold/frontends/default/views/form_messages_on_create.js.rjs +0 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/form_messages_on_update.js.rjs +0 -2
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/live_search.rb +0 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/live_search.rb +0 -52
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/en.rb +0 -66
- data/vendor/plugins/active_scaffold/lib/extensions/name_option_for_datetime.rb +0 -12
- data/vendor/plugins/active_scaffold/test/misc/active_record_permissions.rb +0 -154
@@ -3,9 +3,10 @@ module ActiveScaffold::Config
|
|
3
3
|
self.crud_type = :read
|
4
4
|
|
5
5
|
def initialize(core_config)
|
6
|
-
|
7
|
-
|
8
|
-
@
|
6
|
+
super
|
7
|
+
@text_search = self.class.text_search
|
8
|
+
@live = self.class.live?
|
9
|
+
@split_terms = self.class.split_terms
|
9
10
|
|
10
11
|
# start with the ActionLink defined globally
|
11
12
|
@link = self.class.link.clone
|
@@ -16,13 +17,22 @@ module ActiveScaffold::Config
|
|
16
17
|
# --------------------------
|
17
18
|
# the ActionLink for this action
|
18
19
|
cattr_accessor :link
|
19
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :
|
20
|
+
@@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?)
|
21
|
+
|
22
|
+
# A flag for how the search should do full-text searching in the database:
|
23
|
+
# * :full: LIKE %?%
|
24
|
+
# * :start: LIKE ?%
|
25
|
+
# * :end: LIKE %?
|
26
|
+
# * false: LIKE ?
|
27
|
+
# Default is :full
|
28
|
+
cattr_accessor :text_search
|
29
|
+
@@text_search = :full
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
# whether submits the search as you type
|
32
|
+
cattr_writer :live
|
33
|
+
def self.live?
|
34
|
+
@@live
|
24
35
|
end
|
25
|
-
@@full_text_search = true
|
26
36
|
|
27
37
|
# instance-level configuration
|
28
38
|
# ----------------------------
|
@@ -36,17 +46,27 @@ module ActiveScaffold::Config
|
|
36
46
|
@columns
|
37
47
|
end
|
38
48
|
|
39
|
-
|
40
|
-
@columns = ActiveScaffold::DataStructures::ActionColumns.new(*val)
|
41
|
-
@columns.action = self
|
42
|
-
end
|
49
|
+
public :columns=
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
51
|
+
# A flag for how the search should do full-text searching in the database:
|
52
|
+
# * :full: LIKE %?%
|
53
|
+
# * :start: LIKE ?%
|
54
|
+
# * :end: LIKE %?
|
55
|
+
# * false: LIKE ?
|
56
|
+
# Default is :full
|
57
|
+
attr_accessor :text_search
|
58
|
+
|
59
|
+
@@split_terms = " "
|
60
|
+
cattr_accessor :split_terms
|
61
|
+
attr_accessor :split_terms
|
48
62
|
|
49
63
|
# the ActionLink for this action
|
50
64
|
attr_accessor :link
|
65
|
+
|
66
|
+
# whether submits the search as you type
|
67
|
+
attr_writer :live
|
68
|
+
def live?
|
69
|
+
@live
|
70
|
+
end
|
51
71
|
end
|
52
72
|
end
|
@@ -3,37 +3,30 @@ module ActiveScaffold::Config
|
|
3
3
|
self.crud_type = :read
|
4
4
|
|
5
5
|
def initialize(core_config)
|
6
|
-
|
7
|
-
|
6
|
+
super
|
8
7
|
# start with the ActionLink defined globally
|
9
8
|
@link = self.class.link.clone
|
9
|
+
@label = :show_model
|
10
10
|
end
|
11
11
|
|
12
12
|
# global level configuration
|
13
13
|
# --------------------------
|
14
14
|
cattr_accessor :link
|
15
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('show', :label => :show, :type => :
|
16
|
-
|
15
|
+
@@link = ActiveScaffold::DataStructures::ActionLink.new('show', :label => :show, :type => :member, :security_method => :show_authorized?)
|
17
16
|
# instance-level configuration
|
18
17
|
# ----------------------------
|
19
18
|
|
20
19
|
# the ActionLink for this action
|
21
20
|
attr_accessor :link
|
22
|
-
|
23
21
|
# the label for this action. used for the header.
|
24
22
|
attr_writer :label
|
25
|
-
def label
|
26
|
-
@label ? as_(@label) : as_(:show_model, :model => @core.label(:count => 1))
|
27
|
-
end
|
28
23
|
|
29
24
|
# provides access to the list of columns specifically meant for this action to use
|
30
25
|
def columns
|
31
26
|
self.columns = @core.columns._inheritable unless @columns # lazy evaluation
|
32
27
|
@columns
|
33
28
|
end
|
34
|
-
|
35
|
-
|
36
|
-
@columns.action = self
|
37
|
-
end
|
29
|
+
|
30
|
+
public :columns=
|
38
31
|
end
|
39
32
|
end
|
@@ -1,15 +1,21 @@
|
|
1
1
|
module ActiveScaffold::Config
|
2
2
|
class Subform < Base
|
3
3
|
def initialize(core_config)
|
4
|
-
|
4
|
+
super
|
5
|
+
@layout = self.class.layout # default layout
|
5
6
|
end
|
6
7
|
|
7
8
|
# global level configuration
|
8
9
|
# --------------------------
|
9
10
|
|
11
|
+
cattr_accessor :layout
|
12
|
+
@@layout = :horizontal
|
13
|
+
|
10
14
|
# instance-level configuration
|
11
15
|
# ----------------------------
|
12
16
|
|
17
|
+
attr_accessor :layout
|
18
|
+
|
13
19
|
# provides access to the list of columns specifically meant for the Sub-Form to use
|
14
20
|
def columns
|
15
21
|
# we want to delay initializing to the @core.update.columns set for as long as possible. but we have to eventually clone, or else have a configuration "leak"
|
@@ -24,10 +30,6 @@ module ActiveScaffold::Config
|
|
24
30
|
@columns
|
25
31
|
end
|
26
32
|
|
27
|
-
|
28
|
-
@columns = ActiveScaffold::DataStructures::ActionColumns.new(*val)
|
29
|
-
@columns.action = self
|
30
|
-
return @columns
|
31
|
-
end
|
33
|
+
public :columns=
|
32
34
|
end
|
33
35
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module ActiveScaffold::Config
|
2
|
-
class Update < Form
|
2
|
+
class Update < ActiveScaffold::Config::Form
|
3
3
|
self.crud_type = :update
|
4
|
-
def initialize(
|
4
|
+
def initialize(core_config)
|
5
5
|
super
|
6
6
|
self.nested_links = self.class.nested_links
|
7
|
+
self.persistent = self.class.persistent
|
8
|
+
@label = :update_model
|
7
9
|
end
|
8
10
|
|
9
11
|
# global level configuration
|
@@ -15,18 +17,20 @@ module ActiveScaffold::Config
|
|
15
17
|
def self.link=(val)
|
16
18
|
@@link = val
|
17
19
|
end
|
18
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :
|
20
|
+
@@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?)
|
19
21
|
|
22
|
+
# whether the form stays open after an update or not
|
23
|
+
cattr_accessor :persistent
|
24
|
+
@@persistent = false
|
25
|
+
|
20
26
|
# instance-level configuration
|
21
27
|
# ----------------------------
|
22
28
|
|
23
|
-
# the label= method already exists in the Form base class
|
24
|
-
def label
|
25
|
-
@label ? as_(@label) : as_(:update_model, :model => @core.label(:count => 1))
|
26
|
-
end
|
27
|
-
|
28
29
|
attr_accessor :nested_links
|
29
30
|
cattr_accessor :nested_links
|
30
31
|
@@nested_links = false
|
32
|
+
|
33
|
+
# whether the form stays open after an update or not
|
34
|
+
attr_accessor :persistent
|
31
35
|
end
|
32
36
|
end
|
@@ -8,7 +8,7 @@ module ActiveScaffold
|
|
8
8
|
def configure(&configuration_block)
|
9
9
|
return unless configuration_block
|
10
10
|
@configuration_binding = configuration_block.binding
|
11
|
-
ret =
|
11
|
+
ret = instance_exec self, &configuration_block
|
12
12
|
@configuration_binding = nil
|
13
13
|
return ret
|
14
14
|
end
|
@@ -26,4 +26,4 @@ module ActiveScaffold
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
@@ -1,178 +1,173 @@
|
|
1
|
-
module ActiveScaffold
|
2
|
-
module Constraints
|
3
|
-
def self.included(base)
|
4
|
-
base.module_eval do
|
5
|
-
before_filter :register_constraints_with_action_columns
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
protected
|
10
|
-
|
11
|
-
# Returns the current constraints
|
12
|
-
def active_scaffold_constraints
|
13
|
-
return active_scaffold_session_storage[:constraints] || {}
|
14
|
-
end
|
15
|
-
|
16
|
-
# For each enabled action, adds the constrained columns to the ActionColumns object (if it exists).
|
17
|
-
# This lets the ActionColumns object skip constrained columns.
|
18
|
-
#
|
19
|
-
# If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column.
|
20
|
-
def register_constraints_with_action_columns
|
21
|
-
constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym}
|
22
|
-
|
23
|
-
if self.class.uses_active_scaffold?
|
24
|
-
# we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't
|
25
|
-
active_scaffold_config.actions.each do |action_name|
|
26
|
-
action = active_scaffold_config.send(action_name)
|
27
|
-
next unless action.respond_to? :columns
|
28
|
-
action.columns.constraint_columns = constrained_fields
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns search conditions based on the current scaffold constraints.
|
34
|
-
#
|
35
|
-
# Supports constraints based on either a column name (in which case it checks for an association
|
36
|
-
# or just uses the search_sql) or a database field name.
|
37
|
-
#
|
38
|
-
# All of this work is primarily to support nested scaffolds in a manner generally useful for other
|
39
|
-
# embedded scaffolds.
|
40
|
-
def conditions_from_constraints
|
41
|
-
conditions = nil
|
42
|
-
active_scaffold_constraints.each do |k, v|
|
43
|
-
column = active_scaffold_config.columns[k]
|
44
|
-
constraint_condition = if column
|
45
|
-
# Assume this is a multi-level association constraint.
|
46
|
-
# example:
|
47
|
-
# data model: Park -> Den -> Bear
|
48
|
-
# constraint: :den => {:park => 5}
|
49
|
-
if v.is_a? Hash
|
50
|
-
far_association = column.association.klass.reflect_on_association(v.keys.first)
|
51
|
-
field = far_association.klass.primary_key
|
52
|
-
table = far_association.table_name
|
53
|
-
|
54
|
-
|
55
|
-
constraint_condition_for("#{table}.#{field}", v.values.first)
|
56
|
-
|
57
|
-
# association column constraint
|
58
|
-
elsif column.association
|
59
|
-
if column.association.macro == :has_and_belongs_to_many
|
60
|
-
active_scaffold_habtm_joins.concat column.includes
|
61
|
-
else
|
62
|
-
|
63
|
-
end
|
64
|
-
condition_from_association_constraint(column.association, v)
|
65
|
-
|
66
|
-
# regular column constraints
|
67
|
-
elsif column.searchable?
|
68
|
-
|
69
|
-
constraint_condition_for(column.search_sql, v)
|
70
|
-
end
|
71
|
-
# unknown-to-activescaffold-but-real-database-column constraint
|
72
|
-
elsif active_scaffold_config.model.column_names.include? k.to_s
|
73
|
-
constraint_condition_for(k.to_s, v)
|
74
|
-
else
|
75
|
-
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
|
76
|
-
end
|
77
|
-
|
78
|
-
conditions = merge_conditions(conditions, constraint_condition)
|
79
|
-
end
|
80
|
-
|
81
|
-
conditions
|
82
|
-
end
|
83
|
-
|
84
|
-
# We do NOT want to use .search_sql. If anything, search_sql will refer
|
85
|
-
# to a human-searchable value on the associated record.
|
86
|
-
def condition_from_association_constraint(association, value)
|
87
|
-
# when the reverse association is a :belongs_to, the id for the associated object only exists as
|
88
|
-
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
|
89
|
-
# we have to use the other model's primary_key.
|
90
|
-
#
|
91
|
-
# please see the relevant tests for concrete examples.
|
92
|
-
field = if [:has_one, :has_many].include?(association.macro)
|
93
|
-
association.klass.primary_key
|
94
|
-
|
95
|
-
association.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
#
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
def constraint_condition_for(sql, value)
|
175
|
-
value.nil? ? "#{sql} IS NULL" : ["#{sql} = ?", value]
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
1
|
+
module ActiveScaffold
|
2
|
+
module Constraints
|
3
|
+
def self.included(base)
|
4
|
+
base.module_eval do
|
5
|
+
before_filter :register_constraints_with_action_columns
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
# Returns the current constraints
|
12
|
+
def active_scaffold_constraints
|
13
|
+
return active_scaffold_session_storage[:constraints] || {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# For each enabled action, adds the constrained columns to the ActionColumns object (if it exists).
|
17
|
+
# This lets the ActionColumns object skip constrained columns.
|
18
|
+
#
|
19
|
+
# If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column.
|
20
|
+
def register_constraints_with_action_columns
|
21
|
+
constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym}
|
22
|
+
|
23
|
+
if self.class.uses_active_scaffold?
|
24
|
+
# we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't
|
25
|
+
active_scaffold_config.actions.each do |action_name|
|
26
|
+
action = active_scaffold_config.send(action_name)
|
27
|
+
next unless action.respond_to? :columns
|
28
|
+
action.columns.constraint_columns = constrained_fields
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns search conditions based on the current scaffold constraints.
|
34
|
+
#
|
35
|
+
# Supports constraints based on either a column name (in which case it checks for an association
|
36
|
+
# or just uses the search_sql) or a database field name.
|
37
|
+
#
|
38
|
+
# All of this work is primarily to support nested scaffolds in a manner generally useful for other
|
39
|
+
# embedded scaffolds.
|
40
|
+
def conditions_from_constraints
|
41
|
+
conditions = nil
|
42
|
+
active_scaffold_constraints.each do |k, v|
|
43
|
+
column = active_scaffold_config.columns[k]
|
44
|
+
constraint_condition = if column
|
45
|
+
# Assume this is a multi-level association constraint.
|
46
|
+
# example:
|
47
|
+
# data model: Park -> Den -> Bear
|
48
|
+
# constraint: :den => {:park => 5}
|
49
|
+
if v.is_a? Hash
|
50
|
+
far_association = column.association.klass.reflect_on_association(v.keys.first)
|
51
|
+
field = far_association.klass.primary_key
|
52
|
+
table = far_association.table_name
|
53
|
+
|
54
|
+
active_scaffold_includes.concat([{k => v.keys.first}]) # e.g. {:den => :park}
|
55
|
+
constraint_condition_for("#{table}.#{field}", v.values.first)
|
56
|
+
|
57
|
+
# association column constraint
|
58
|
+
elsif column.association
|
59
|
+
if column.association.macro == :has_and_belongs_to_many
|
60
|
+
active_scaffold_habtm_joins.concat column.includes
|
61
|
+
else
|
62
|
+
active_scaffold_includes.concat column.includes
|
63
|
+
end
|
64
|
+
condition_from_association_constraint(column.association, v)
|
65
|
+
|
66
|
+
# regular column constraints
|
67
|
+
elsif column.searchable?
|
68
|
+
active_scaffold_includes.concat column.includes
|
69
|
+
constraint_condition_for(column.search_sql, v)
|
70
|
+
end
|
71
|
+
# unknown-to-activescaffold-but-real-database-column constraint
|
72
|
+
elsif active_scaffold_config.model.column_names.include? k.to_s
|
73
|
+
constraint_condition_for(k.to_s, v)
|
74
|
+
else
|
75
|
+
raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller
|
76
|
+
end
|
77
|
+
|
78
|
+
conditions = merge_conditions(conditions, constraint_condition)
|
79
|
+
end
|
80
|
+
|
81
|
+
conditions
|
82
|
+
end
|
83
|
+
|
84
|
+
# We do NOT want to use .search_sql. If anything, search_sql will refer
|
85
|
+
# to a human-searchable value on the associated record.
|
86
|
+
def condition_from_association_constraint(association, value)
|
87
|
+
# when the reverse association is a :belongs_to, the id for the associated object only exists as
|
88
|
+
# the primary_key on the other table. so for :has_one and :has_many (when the reverse is :belongs_to),
|
89
|
+
# we have to use the other model's primary_key.
|
90
|
+
#
|
91
|
+
# please see the relevant tests for concrete examples.
|
92
|
+
field = if [:has_one, :has_many].include?(association.macro)
|
93
|
+
association.klass.primary_key
|
94
|
+
elsif [:has_and_belongs_to_many].include?(association.macro)
|
95
|
+
association.association_foreign_key
|
96
|
+
else
|
97
|
+
association.options[:foreign_key] || association.name.to_s.foreign_key
|
98
|
+
end
|
99
|
+
|
100
|
+
table = case association.macro
|
101
|
+
when :has_and_belongs_to_many
|
102
|
+
association.options[:join_table]
|
103
|
+
|
104
|
+
when :belongs_to
|
105
|
+
active_scaffold_config.model.table_name
|
106
|
+
|
107
|
+
else
|
108
|
+
association.table_name
|
109
|
+
end
|
110
|
+
|
111
|
+
if association.options[:primary_key]
|
112
|
+
value = association.klass.find(value).send(association.options[:primary_key])
|
113
|
+
end
|
114
|
+
|
115
|
+
condition = constraint_condition_for("#{table}.#{field}", value)
|
116
|
+
if association.options[:polymorphic]
|
117
|
+
condition = merge_conditions(
|
118
|
+
condition,
|
119
|
+
constraint_condition_for("#{table}.#{association.name}_type", params[:parent_model].to_s)
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
condition
|
124
|
+
end
|
125
|
+
|
126
|
+
def constraint_error(klass, column_name)
|
127
|
+
"Malformed constraint `#{klass}##{column_name}'. If it's a legitimate column, and you are using a nested scaffold, please specify or double-check the reverse association name."
|
128
|
+
end
|
129
|
+
|
130
|
+
# Applies constraints to the given record.
|
131
|
+
#
|
132
|
+
# Searches through the known columns for association columns. If the given constraint is an association,
|
133
|
+
# it assumes that the constraint value is an id. It then does a association.klass.find with the value
|
134
|
+
# and adds the associated object to the record.
|
135
|
+
#
|
136
|
+
# For some operations ActiveRecord will automatically update the database. That's not always ok.
|
137
|
+
# If it *is* ok (e.g. you're in a transaction), then set :allow_autosave to true.
|
138
|
+
def apply_constraints_to_record(record, options = {})
|
139
|
+
options[:allow_autosave] = false if options[:allow_autosave].nil?
|
140
|
+
|
141
|
+
active_scaffold_constraints.each do |k, v|
|
142
|
+
column = active_scaffold_config.columns[k]
|
143
|
+
if column and column.association
|
144
|
+
if column.plural_association?
|
145
|
+
record.send("#{k}").send(:<<, column.association.klass.find(v))
|
146
|
+
elsif column.association.options[:polymorphic]
|
147
|
+
record.send("#{k}=", params[:parent_model].constantize.find(v))
|
148
|
+
else # regular singular association
|
149
|
+
record.send("#{k}=", column.association.klass.find(v))
|
150
|
+
|
151
|
+
# setting the belongs_to side of a has_one isn't safe. if the has_one was already
|
152
|
+
# specified, rails won't automatically clear out the previous associated record.
|
153
|
+
#
|
154
|
+
# note that we can't take the extra step to correct this unless we're permitted to
|
155
|
+
# run operations where activerecord auto-saves the object.
|
156
|
+
reverse = column.association.klass.reflect_on_association(column.association.reverse)
|
157
|
+
if reverse.macro == :has_one and options[:allow_autosave]
|
158
|
+
record.send(k).send("#{column.association.reverse}=", record)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
else
|
162
|
+
record.send("#{k}=", v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def constraint_condition_for(sql, value)
|
170
|
+
value.nil? ? "#{sql} IS NULL" : ["#{sql} = ?", value]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|