active_scaffold 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +27 -0
- data/CHANGELOG +152 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README +51 -0
- data/Rakefile +24 -0
- data/active_scaffold.gemspec +24 -0
- data/environment.rb +22 -0
- data/frontends/default/images/add.gif +0 -0
- data/frontends/default/images/arrow_down.gif +0 -0
- data/frontends/default/images/arrow_up.gif +0 -0
- data/frontends/default/images/close.gif +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/indicator-small.gif +0 -0
- data/frontends/default/images/indicator.gif +0 -0
- data/frontends/default/images/magnifier.png +0 -0
- data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +726 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +954 -0
- data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
- data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
- data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
- data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
- data/frontends/default/stylesheets/stylesheet.css +858 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +41 -0
- data/frontends/default/views/_create_form.html.erb +6 -0
- data/frontends/default/views/_create_form_on_list.html.erb +5 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +24 -0
- data/frontends/default/views/_form_association.html.erb +14 -0
- data/frontends/default/views/_form_association_footer.html.erb +40 -0
- data/frontends/default/views/_form_attribute.html.erb +15 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +19 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
- data/frontends/default/views/_human_conditions.html.erb +1 -0
- data/frontends/default/views/_list.html.erb +18 -0
- data/frontends/default/views/_list_actions.html.erb +16 -0
- data/frontends/default/views/_list_calculations.html.erb +16 -0
- data/frontends/default/views/_list_column_headings.html.erb +12 -0
- data/frontends/default/views/_list_header.html.erb +12 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
- data/frontends/default/views/_list_messages.html.erb +32 -0
- data/frontends/default/views/_list_pagination.html.erb +11 -0
- data/frontends/default/views/_list_pagination_links.html.erb +9 -0
- data/frontends/default/views/_list_record.html.erb +14 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +32 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_render_field.js.rjs +13 -0
- data/frontends/default/views/_row.html.erb +12 -0
- data/frontends/default/views/_search.html.erb +34 -0
- data/frontends/default/views/_search_attribute.html.erb +10 -0
- data/frontends/default/views/_show.html.erb +8 -0
- data/frontends/default/views/_show_columns.html.erb +12 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +5 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/frontends/default/views/add_existing.js.rjs +17 -0
- data/frontends/default/views/add_existing_form.html.erb +5 -0
- data/frontends/default/views/create.html.erb +5 -0
- data/frontends/default/views/delete.html.erb +13 -0
- data/frontends/default/views/destroy.js.rjs +5 -0
- data/frontends/default/views/edit_associated.js.rjs +11 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.rjs +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/list.js.rjs +1 -0
- data/frontends/default/views/on_action_update.js.rjs +8 -0
- data/frontends/default/views/on_create.js.rjs +24 -0
- data/frontends/default/views/on_update.js.rjs +15 -0
- data/frontends/default/views/search.html.erb +5 -0
- data/frontends/default/views/show.html.erb +5 -0
- data/frontends/default/views/update.html.erb +8 -0
- data/frontends/default/views/update_column.js.rjs +13 -0
- data/frontends/default/views/update_row.js.rjs +1 -0
- data/init.rb +1 -0
- data/install_assets.rb +44 -0
- data/lib/active_record_permissions.rb +134 -0
- data/lib/active_scaffold.rb +279 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +150 -0
- data/lib/active_scaffold/actions/create.rb +152 -0
- data/lib/active_scaffold/actions/delete.rb +72 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +128 -0
- data/lib/active_scaffold/actions/mark.rb +50 -0
- data/lib/active_scaffold/actions/nested.rb +241 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +54 -0
- data/lib/active_scaffold/actions/subform.rb +17 -0
- data/lib/active_scaffold/actions/update.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +207 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/bridge.rb +52 -0
- data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
- data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
- data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
- data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
- data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
- data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
- data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
- data/lib/active_scaffold/config/base.rb +54 -0
- data/lib/active_scaffold/config/core.rb +229 -0
- data/lib/active_scaffold/config/create.rb +43 -0
- data/lib/active_scaffold/config/delete.rb +25 -0
- data/lib/active_scaffold/config/field_search.rb +74 -0
- data/lib/active_scaffold/config/form.rb +46 -0
- data/lib/active_scaffold/config/list.rb +174 -0
- data/lib/active_scaffold/config/mark.rb +22 -0
- data/lib/active_scaffold/config/nested.rb +43 -0
- data/lib/active_scaffold/config/search.rb +68 -0
- data/lib/active_scaffold/config/show.rb +34 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +38 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +179 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
- data/lib/active_scaffold/data_structures/action_link.rb +162 -0
- data/lib/active_scaffold/data_structures/action_links.rb +59 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +348 -0
- data/lib/active_scaffold/data_structures/columns.rb +75 -0
- data/lib/active_scaffold/data_structures/error_message.rb +24 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +108 -0
- data/lib/active_scaffold/data_structures/set.rb +62 -0
- data/lib/active_scaffold/data_structures/sorting.rb +168 -0
- data/lib/active_scaffold/finder.rb +333 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +343 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +363 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +238 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +315 -0
- data/lib/active_scaffold/locale/de.rb +113 -0
- data/lib/active_scaffold/locale/en.rb +118 -0
- data/lib/active_scaffold/locale/es.yml +112 -0
- data/lib/active_scaffold/locale/fr.rb +113 -0
- data/lib/active_scaffold/locale/hu.yml +63 -0
- data/lib/active_scaffold/locale/ja.yml +64 -0
- data/lib/active_scaffold/locale/ru.yml +62 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/dhtml_confirm.rb +54 -0
- data/lib/extensions/action_controller_rendering.rb +20 -0
- data/lib/extensions/action_view_rendering.rb +113 -0
- data/lib/extensions/action_view_resolver.rb +7 -0
- data/lib/extensions/active_record_offset.rb +12 -0
- data/lib/extensions/array.rb +7 -0
- data/lib/extensions/localize.rb +10 -0
- data/lib/extensions/name_option_for_datetime.rb +12 -0
- data/lib/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/extensions/paginator_extensions.rb +26 -0
- data/lib/extensions/reverse_associations.rb +62 -0
- data/lib/extensions/routing_mapper.rb +34 -0
- data/lib/extensions/to_label.rb +8 -0
- data/lib/extensions/unsaved_associated.rb +61 -0
- data/lib/extensions/unsaved_record.rb +20 -0
- data/lib/extensions/usa_state.rb +46 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
- data/lib/paginator.rb +136 -0
- data/lib/responds_to_parent.rb +70 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/test/bridges/bridge_test.rb +47 -0
- data/test/config/base_test.rb +15 -0
- data/test/config/create_test.rb +55 -0
- data/test/config/list_test.rb +74 -0
- data/test/config/show_test.rb +43 -0
- data/test/config/update_test.rb +17 -0
- data/test/const_mocker.rb +36 -0
- data/test/data_structures/action_columns_test.rb +113 -0
- data/test/data_structures/action_link_test.rb +78 -0
- data/test/data_structures/action_links_test.rb +78 -0
- data/test/data_structures/actions_test.rb +25 -0
- data/test/data_structures/association_column_test.rb +42 -0
- data/test/data_structures/column_test.rb +185 -0
- data/test/data_structures/columns_test.rb +69 -0
- data/test/data_structures/error_message_test.rb +28 -0
- data/test/data_structures/set_test.rb +86 -0
- data/test/data_structures/sorting_test.rb +126 -0
- data/test/data_structures/standard_column_test.rb +24 -0
- data/test/data_structures/virtual_column_test.rb +23 -0
- data/test/extensions/active_record_test.rb +45 -0
- data/test/extensions/array_test.rb +12 -0
- data/test/helpers/form_column_helpers_test.rb +31 -0
- data/test/helpers/list_column_helpers_test.rb +31 -0
- data/test/helpers/pagination_helpers_test.rb +55 -0
- data/test/misc/active_record_permissions_test.rb +154 -0
- data/test/misc/attribute_params_test.rb +110 -0
- data/test/misc/configurable_test.rb +96 -0
- data/test/misc/constraints_test.rb +193 -0
- data/test/misc/finder_test.rb +93 -0
- data/test/misc/lang_test.rb +12 -0
- data/test/mock_app/.gitignore +2 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +16 -0
- data/test/mock_app/config/environment.rb +43 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +43 -0
- data/test/mock_app/db/test.sqlite3 +1 -0
- data/test/mock_app/public/blank.html +33 -0
- data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
- data/test/model_stub.rb +55 -0
- data/test/run_all.rb +8 -0
- data/test/test_helper.rb +39 -0
- data/uninstall.rb +13 -0
- metadata +478 -0
data/.autotest
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class Autotest
|
|
2
|
+
##
|
|
3
|
+
# Convert a path in a string, s, into a class name, changing
|
|
4
|
+
# underscores to CamelCase, etc.
|
|
5
|
+
|
|
6
|
+
def path_to_classname(s)
|
|
7
|
+
sep = File::SEPARATOR
|
|
8
|
+
f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
|
|
9
|
+
f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
|
|
10
|
+
f = f.map { |path| path =~ /Test$/ ? path : "#{path}Test" }
|
|
11
|
+
f.join('::')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Autotest.add_hook :initialize do |at|
|
|
16
|
+
# doesn't seem to work
|
|
17
|
+
# at.clear_mappings
|
|
18
|
+
|
|
19
|
+
at.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
|
|
20
|
+
possible = File.basename(filename, 'rb').gsub '_', '_?'
|
|
21
|
+
files_matching %r%^test/.*#{possible}_test\.rb$%
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
at.add_mapping(/^test.*\/.*_test\.rb$/) do |filename, _|
|
|
25
|
+
filename
|
|
26
|
+
end
|
|
27
|
+
end
|
data/CHANGELOG
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
= 1.2RC1
|
|
2
|
+
|
|
3
|
+
== FEATURES
|
|
4
|
+
|
|
5
|
+
- Added view helpers (active_scaffold_javascripts, active_scaffold_stylesheets, active_scaffold_ie_stylesheets) to help with asset cacheing (Alexander Semyonov)
|
|
6
|
+
- Works with Rails 2.1 (2.0 / 1.2.x will continue to be supported by version 1.1)
|
|
7
|
+
|
|
8
|
+
== FIXES
|
|
9
|
+
|
|
10
|
+
- Javascript compatibility with FF3 / Safari 3.1 (Mike Dalessio)
|
|
11
|
+
see http://groups.google.com/group/activescaffold/browse_thread/thread/d37afa3f2ac687f2/b34ebf62d767bee3
|
|
12
|
+
- Avoid ruby deprecation warning in config/list.rb (Dustin Sallings)
|
|
13
|
+
- Fixes bug where template overrides are ignored when placed in Engines plugins (Mike Dalessio)
|
|
14
|
+
- Fixed in_place_editor to work with latest control.js
|
|
15
|
+
- Fixed infinite recursion bug when creating a new record with a new association
|
|
16
|
+
- Subform action name conflict fix
|
|
17
|
+
- Helpful warning message if record_select is not on a column with an association
|
|
18
|
+
|
|
19
|
+
= 1.1.1
|
|
20
|
+
|
|
21
|
+
== FIXES
|
|
22
|
+
|
|
23
|
+
* rendering for rails 1.2.x
|
|
24
|
+
|
|
25
|
+
= 1.1.0
|
|
26
|
+
|
|
27
|
+
== FEATURES
|
|
28
|
+
|
|
29
|
+
* `render :super' now accepts a :locals option
|
|
30
|
+
* parameter-based conditions now support arrays of values (e.g. users?name[]=bob&name[]=fred becomes "name IN ('bob', 'fred')")
|
|
31
|
+
|
|
32
|
+
== FIXES
|
|
33
|
+
|
|
34
|
+
* `render :super' now works from active_scaffold_overrides without endlessly looping
|
|
35
|
+
* `render :super' no longer assumes that the *immediate* caller was the override template file
|
|
36
|
+
* `render :super' works better with windows file names (e.g. c:/...)
|
|
37
|
+
* reload_if_empty() javascript now uses GET
|
|
38
|
+
* inplace_edit now uses POST instead of GET
|
|
39
|
+
* adding time and date fields to ignore list for determining whether subform row is empty. previously only datetime was ignored.
|
|
40
|
+
* closed a potential internet explorer security issue in dhtml_history.js library
|
|
41
|
+
|
|
42
|
+
= 1.1.0 RC1
|
|
43
|
+
|
|
44
|
+
== FEATURES
|
|
45
|
+
|
|
46
|
+
=== LIST
|
|
47
|
+
* row class: new helper method (list_row_class) gets called for each record in the list and returns a CSS class.
|
|
48
|
+
* automatically link to the :show action of singular associations. this is similar to the nested scaffolds for plural associations.
|
|
49
|
+
* column.list_ui: good for when you want to render multiple columns the same way.
|
|
50
|
+
* * built-in list interface options:
|
|
51
|
+
* * * for inplace edits - checkbox
|
|
52
|
+
* Support :joins_for_collection in column_calculation
|
|
53
|
+
* inplace_edit option on list columns. currently works for text boxes and booleans
|
|
54
|
+
|
|
55
|
+
=== CREATE/UPDATE
|
|
56
|
+
* file uploads - largely taken care of by file_column bridge.
|
|
57
|
+
* * automatically detects if FileColumn is installed. If so, uses it, and sets the form_ui for file columns to be file upload fields
|
|
58
|
+
* * sets multipart? on config.create and config.update if file_columns are used on the target model
|
|
59
|
+
* * Posts through iframe to give ajax-style file uploads
|
|
60
|
+
* * Image columns are recognized and previewed as such
|
|
61
|
+
* * Ability to delete a file
|
|
62
|
+
* form_ui
|
|
63
|
+
* * form interface options are now supported through helper method named active_scaffold_input_#{form_ui}. if you want a different form interface than activescaffold normally provides, you may configure the form_ui for that column to use one of these methods. you can easily define your own, too.
|
|
64
|
+
* * built-in form interface options:
|
|
65
|
+
* * * for associations - singular_association, plural_association, select, record_select
|
|
66
|
+
* * * others - select, checkbox, country, password, textarea, usa_state, virtual, boolean
|
|
67
|
+
* * subforms respect form_ui settings. but if form_ui is empty, it will be set to :select to disable subform nesting.
|
|
68
|
+
* boolean columns: when the database column allows nil, we now add a third option to the dropdown so you don't *have* to pick true or false.
|
|
69
|
+
* new :params option for a column lets you specify additional parameters to accept when the given column is on the form. this is for when a column needs to submit multiple values to work.
|
|
70
|
+
* improved support for associations in parameters. for simply selecting/deselecting associations, activescaffold will now recognize `:user => 5' or `:users => [1, 2, 5]'.
|
|
71
|
+
* Supply a unique id from active_scaffold_input_options for form fields.
|
|
72
|
+
* added after_update_save controller override method
|
|
73
|
+
|
|
74
|
+
=== EMBEDDING
|
|
75
|
+
* `render :active_scaffold' now accepts a :conditions option, which is a weaker but more flexible variation of :constraints
|
|
76
|
+
* active_scaffold_includes now accepts a frontend name. this is necessary so you can include the proper assets even if active_scaffold isn't configured on the current controller (it's embedded).
|
|
77
|
+
* polymorphic constraints are now supported, assuming params[:parent_model].to_s is the proper content for the polymorphic _type field.
|
|
78
|
+
* Beefing up the constraint system so it can handle has_one/belongs_to. Specifically, it can now disassociate a previous relationship before setting a new one. For example, Bear has_one Den. If creating a new Den, constrained to a certain Bear, the constraints system will now disassociate any previous Den from the Bear before associating the new one.
|
|
79
|
+
|
|
80
|
+
=== NESTING
|
|
81
|
+
* :through associations may now be nested
|
|
82
|
+
* nested#shallow_delete
|
|
83
|
+
|
|
84
|
+
=== SEARCH
|
|
85
|
+
* fieldsearch module handles booleans better - provides third option so you don't *have* to search on a boolean column
|
|
86
|
+
* In field search lock_version is the only magic column. May want to search by :id or date fields.
|
|
87
|
+
|
|
88
|
+
=== GENERAL
|
|
89
|
+
* use #human_name for the column label when possible.
|
|
90
|
+
* merge_conditions now supports hash conditions (and should forever support every conditions style that ActiveRecord supports)
|
|
91
|
+
* action links may now remove an action link with #clear_link
|
|
92
|
+
* action links have a new :controller option, so you don't have to sneak it into :params anymore
|
|
93
|
+
* dhtml history may now be disabled
|
|
94
|
+
* authorized_for? in ActiveRecordPermissions now calls respond_to? only as much as needed
|
|
95
|
+
* removing an assert_valid_keys? call in active_record_permissions#authorized_for?. it just wasn't worth the CPU time.
|
|
96
|
+
* render :super is now extension-agnostic. ex: `render :super` in list.html.erb will properly find list.rhtml as the "parent" template.
|
|
97
|
+
* Auto-bridge loading mechanism. Bridges integrated into core.
|
|
98
|
+
* inherited_view_paths: ability to specify other folders to look for if missing view occurs
|
|
99
|
+
|
|
100
|
+
== FIXES
|
|
101
|
+
|
|
102
|
+
=== LIST
|
|
103
|
+
* the calculation row now updates on edit/create/destroy.
|
|
104
|
+
* list now returns to page 1 if the current page has no records.
|
|
105
|
+
* list will now try to reload the scaffold on a previous page if you delete the last entry on the current page.
|
|
106
|
+
* if there were no end-of-line record actions, then any column actions would not use ajax. this was because the loading indicator was missing, which messed up the action link javascript.
|
|
107
|
+
* theme == :default no longer attempts to use Rico.Corner
|
|
108
|
+
* column_empty? now treats any values equal to list.empty_field_text as empty, too.
|
|
109
|
+
* better :method handling for action links.
|
|
110
|
+
* the ' ' fix for ie6 was failing for value types that weren't nil and didn't respond to empty?
|
|
111
|
+
* if someone sets singular columns to link to the 'nested' action, the link will now render with the appropriate id parameter.
|
|
112
|
+
* do not propagate params[:search] through action links that link to other controllers. closes issue #447.
|
|
113
|
+
* reworked rendering of pagination links for IE
|
|
114
|
+
|
|
115
|
+
=== CREATE/UPDATE
|
|
116
|
+
* constraints are now applied to a record during the #new action, in case any custom form rendering depends on the constrained column
|
|
117
|
+
* the default options_for_association_conditions now returns nil for :through associations
|
|
118
|
+
* will not update a record attribute if the value hasn't changed. this is a workaround for an activerecord bug with has_one associations.
|
|
119
|
+
* attributes_hash_is_empty? didn't handle multi-parameter attribute names like 'created_at(5i)', which resulted in extra records being created from subforms.
|
|
120
|
+
* Hide hidden column header labels - like lock_version - in sub-forms.
|
|
121
|
+
* configuring url_for to not escape ampersands for the add_new_url in association footers (the 'create another' button's url)
|
|
122
|
+
* attribute_params.rb#attributes_hash_is_empty now checks defaults by converting them to strings to match the parameter values.
|
|
123
|
+
|
|
124
|
+
=== NESTING
|
|
125
|
+
* no longer trying to nest a polymorphic association (there's no consistent model to list)
|
|
126
|
+
* fixed :conditions generation for nested/embedded scaffolds - was causing a bind variable mismatch.
|
|
127
|
+
|
|
128
|
+
=== SEARCH
|
|
129
|
+
* search/livesearch should no longer choke on virtual columns
|
|
130
|
+
* the search/live_search forms will now ignore params[:search] when generating the submit url
|
|
131
|
+
|
|
132
|
+
=== GENERAL
|
|
133
|
+
* no longer blow up on data strings with unintentional % characters. as_() was sprintf'ing too frequently.
|
|
134
|
+
* link_to no longer blows up on controller symbols
|
|
135
|
+
* activescaffold no longer loses information on columns - `config.columns.add', `config.columns = [...]', and `config.columns.exclude' all now affect the *inheritability* of a column by the other modules (list, create, update, etc.), but all columns remain in config.columns. this also makes _id columns behave better.
|
|
136
|
+
* dhtml history no longer saves null:null:null history bookmark.
|
|
137
|
+
* if there aren't any columns to search on, then activescaffold no longer creates an empty WHERE clause
|
|
138
|
+
* render :update was failing in some cases because activescaffold wasn't expecting blocks to the render call.
|
|
139
|
+
* quoting the scaffold id for report_500_response()
|
|
140
|
+
* adding :update_column => :post to the RESTful routing. closes issue #448.
|
|
141
|
+
|
|
142
|
+
== MISC
|
|
143
|
+
|
|
144
|
+
* reorganized the helpers and extensions
|
|
145
|
+
* ui_type is now only an alias for form_ui
|
|
146
|
+
* improvements to exception messages
|
|
147
|
+
* when initializing in production mode, activescaffold now recovers gracefully if it can't copy asset files
|
|
148
|
+
* RESTful routing is now accomplished in a way that'll let other add-ons extend the meaning of :active_scaffold => true.
|
|
149
|
+
* fixes for edge rails compatibility
|
|
150
|
+
* small improvements for localization accessibility
|
|
151
|
+
* minor string renaming (will affect localization tables, though)
|
|
152
|
+
* closed a few XSS holes
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2006 Richard White
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
******************************************************************************************************
|
|
2
|
+
** For all documentation see the project website: http://github.com/vhochstein/active_scaffold/wiki **
|
|
3
|
+
******************************************************************************************************
|
|
4
|
+
|
|
5
|
+
ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com)
|
|
6
|
+
|
|
7
|
+
Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu)
|
|
8
|
+
http://codinginparadise.org
|
|
9
|
+
|
|
10
|
+
Uses Querystring by Adam Vandenberg
|
|
11
|
+
http://adamv.com/dev/javascript/querystring
|
|
12
|
+
|
|
13
|
+
Uses Paginator by Bruce Williams
|
|
14
|
+
http://paginator.rubyforge.org/
|
|
15
|
+
|
|
16
|
+
Supports RecordSelect by Lance Ivy
|
|
17
|
+
http://code.google.com/p/recordselect/
|
|
18
|
+
|
|
19
|
+
== Version Information
|
|
20
|
+
|
|
21
|
+
Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 2.2
|
|
22
|
+
|
|
23
|
+
Active Scaffold master currently supports rails-2.3.5, but incompatible changes can be introduced, if you want an stable version, use rails-2.3
|
|
24
|
+
Rails 2.3.*: Active Scaffold rails-2.3
|
|
25
|
+
Rails 2.2.*: Active Scaffold rails-2.2
|
|
26
|
+
Rails 2.1.*: Active Scaffold rails-2.1
|
|
27
|
+
Rails < 2.1: Active Scaffold 1-1-stable (no guarantees)
|
|
28
|
+
|
|
29
|
+
Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository:
|
|
30
|
+
script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3
|
|
31
|
+
|
|
32
|
+
Rails 3.0 compatible fork of activesaffold by Volker Hochstein:
|
|
33
|
+
|
|
34
|
+
Since Rails 3.0 render_component is nt used for nesting, but optional for embedded scaffolds
|
|
35
|
+
Rails 3.0 version of render_component:
|
|
36
|
+
rails plugin install git://github.com/vhochstein/render_component.git
|
|
37
|
+
|
|
38
|
+
Since Rails 3.0, the following is needed:
|
|
39
|
+
rails plugin install git://github.com/rails/verification.git
|
|
40
|
+
|
|
41
|
+
Fork uses unobtrusive Javascript, so you are basically free to pick your javascript framework
|
|
42
|
+
Out of the box Prototype or JQuery are supported:
|
|
43
|
+
|
|
44
|
+
Prototype 1.7 (default js framework)
|
|
45
|
+
rails.js in git://github.com/vhochstein/prototype-ujs.git
|
|
46
|
+
|
|
47
|
+
JQuery 1.4.1
|
|
48
|
+
rails.js in git://github.com/vhochstein/jquery-ujs.git
|
|
49
|
+
uncomment last line in ...plugins/active_scaffold/environment.rb in order tu use jquery instead of prototype
|
|
50
|
+
|
|
51
|
+
Released under the MIT license (included)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rake/packagetask'
|
|
4
|
+
require 'rake/rdoctask'
|
|
5
|
+
require 'find'
|
|
6
|
+
|
|
7
|
+
desc 'Default: run unit tests.'
|
|
8
|
+
task :default => :test
|
|
9
|
+
|
|
10
|
+
desc 'Test ActiveScaffold.'
|
|
11
|
+
Rake::TestTask.new(:test) do |t|
|
|
12
|
+
t.libs << 'lib'
|
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
|
14
|
+
t.verbose = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc 'Generate documentation for ActiveScaffold.'
|
|
18
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
20
|
+
rdoc.title = 'ActiveScaffold'
|
|
21
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
22
|
+
rdoc.rdoc_files.include('README')
|
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
24
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = "active_scaffold"
|
|
5
|
+
s.version = "3.0.0"
|
|
6
|
+
s.platform = Gem::Platform::RUBY
|
|
7
|
+
s.authors = ["Many, see README"]
|
|
8
|
+
s.email = ["activescaffold@googlegroups.com"]
|
|
9
|
+
s.homepage = "https://github.com/vhochstein/active_scaffold"
|
|
10
|
+
s.summary = %q{Rails 3 Version of activescaffold supporting prototype and jquery}
|
|
11
|
+
s.description = %q{Advanced scaffolding plugin for Rails}
|
|
12
|
+
|
|
13
|
+
s.files = `git ls-files`.split("\n")
|
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
|
|
18
|
+
s.add_dependency('render_component')
|
|
19
|
+
s.add_dependency('verification')
|
|
20
|
+
s.add_dependency('actionpack', '~> 3.0.0')
|
|
21
|
+
s.add_dependency('activerecord', '~> 3.0.0')
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency('mocha')
|
|
24
|
+
end
|
data/environment.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'active_scaffold'
|
|
2
|
+
|
|
3
|
+
# TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
|
|
4
|
+
Dir["#{File.dirname __FILE__}/lib/extensions/*.rb"].each { |file| require file }
|
|
5
|
+
#Dir["#{File.dirname __FILE__}/lib/generators/*/*.rb"].each { |file| require file }
|
|
6
|
+
Dir["#{File.dirname __FILE__}/lib/active_scaffold/actions/*.rb"].each { |file| require file }
|
|
7
|
+
Dir["#{File.dirname __FILE__}/lib/active_scaffold/data_structures/*.rb"].each { |file| require file }
|
|
8
|
+
Dir["#{File.dirname __FILE__}/lib/active_scaffold/config/*.rb"].each { |file| require file }
|
|
9
|
+
Dir["#{File.dirname __FILE__}/lib/active_scaffold/helpers/*.rb"].each { |file| require file }
|
|
10
|
+
|
|
11
|
+
ActionController::Base.send(:include, ActiveScaffold)
|
|
12
|
+
ActionController::Base.send(:include, RespondsToParent)
|
|
13
|
+
ActionController::Base.send(:include, ActiveScaffold::Helpers::ControllerHelpers)
|
|
14
|
+
ActionView::Base.send(:include, ActiveScaffold::Helpers::ViewHelpers)
|
|
15
|
+
|
|
16
|
+
ActionController::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Controller}
|
|
17
|
+
ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model}
|
|
18
|
+
ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions}
|
|
19
|
+
|
|
20
|
+
require "#{File.dirname __FILE__}/lib/active_scaffold/bridges/bridge.rb"
|
|
21
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')]
|
|
22
|
+
#ActiveScaffold.js_framework = :jquery
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,957 @@
|
|
|
1
|
+
$(document).ready(function() {
|
|
2
|
+
$('form.as_form').live('ajax:loading', function(event) {
|
|
3
|
+
var as_form = $(this).closest("form");
|
|
4
|
+
if (as_form && as_form.attr('data-loading') == 'true') {
|
|
5
|
+
ActiveScaffold.disable_form(as_form);
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
$('form.as_form').live('ajax:complete', function(event) {
|
|
11
|
+
var as_form = $(this).closest("form");
|
|
12
|
+
if (as_form && as_form.attr('data-loading') == 'true') {
|
|
13
|
+
ActiveScaffold.enable_form(as_form);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
$('form.as_form').live('ajax:failure', function(event) {
|
|
17
|
+
var as_div = $(this).closest("div.active-scaffold");
|
|
18
|
+
if (as_div) {
|
|
19
|
+
ActiveScaffold.report_500_response(as_div)
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
$('form.as_form.as_remote_upload').live('submit', function(event) {
|
|
23
|
+
var as_form = $(this).closest("form");
|
|
24
|
+
if (as_form && as_form.attr('data-loading') == 'true') {
|
|
25
|
+
setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10);
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
29
|
+
$('a.as_action').live('ajax:before', function(event) {
|
|
30
|
+
var action_link = ActiveScaffold.ActionLink.get($(this));
|
|
31
|
+
if (action_link) {
|
|
32
|
+
if (action_link.is_disabled()) {
|
|
33
|
+
return false;
|
|
34
|
+
} else {
|
|
35
|
+
// hack: rails jquery defaults to dataType script
|
|
36
|
+
// but activescaffold is returning html content
|
|
37
|
+
// which chrome does nt like
|
|
38
|
+
if (action_link.position) event.data_type = 'dummy';
|
|
39
|
+
if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
|
|
40
|
+
action_link.disable();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
$('a.as_action').live('ajax:success', function(event, response) {
|
|
46
|
+
var action_link = ActiveScaffold.ActionLink.get($(this));
|
|
47
|
+
if (action_link) {
|
|
48
|
+
if (action_link.position) {
|
|
49
|
+
action_link.insert(response);
|
|
50
|
+
if (action_link.hide_target) action_link.target.hide();
|
|
51
|
+
} else {
|
|
52
|
+
action_link.enable();
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
$('a.as_action').live('ajax:complete', function(event) {
|
|
59
|
+
var action_link = ActiveScaffold.ActionLink.get($(this));
|
|
60
|
+
if (action_link) {
|
|
61
|
+
if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
$('a.as_action').live('ajax:failure', function(event) {
|
|
66
|
+
var action_link = ActiveScaffold.ActionLink.get($(this));
|
|
67
|
+
if (action_link) {
|
|
68
|
+
ActiveScaffold.report_500_response(action_link.scaffold_id());
|
|
69
|
+
action_link.enable();
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
});
|
|
73
|
+
$('a.as_cancel').live('ajax:before', function(event) {
|
|
74
|
+
var as_cancel = $(this);
|
|
75
|
+
var action_link = ActiveScaffold.find_action_link(as_cancel);
|
|
76
|
+
|
|
77
|
+
if (action_link) {
|
|
78
|
+
var cancel_url = as_cancel.attr('href');
|
|
79
|
+
var refresh_data = as_cancel.attr('data-refresh');
|
|
80
|
+
if (refresh_data === 'true' && action_link.refresh_url) {
|
|
81
|
+
event.data_url = action_link.refresh_url;
|
|
82
|
+
if (action_link.position) event.data_type = 'html'
|
|
83
|
+
} else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) {
|
|
84
|
+
action_link.close();
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
});
|
|
90
|
+
$('a.as_cancel').live('ajax:success', function(event, response) {
|
|
91
|
+
var action_link = ActiveScaffold.find_action_link($(this));
|
|
92
|
+
|
|
93
|
+
if (action_link) {
|
|
94
|
+
if (action_link.position) {
|
|
95
|
+
action_link.close(response);
|
|
96
|
+
} else {
|
|
97
|
+
response.evalResponse();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
});
|
|
102
|
+
$('a.as_cancel').live('ajax:failure', function(event) {
|
|
103
|
+
var action_link = ActiveScaffold.find_action_link($(this));
|
|
104
|
+
if (action_link) {
|
|
105
|
+
ActiveScaffold.report_500_response(action_link.scaffold_id());
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
});
|
|
109
|
+
$('a.as_sort').live('ajax:before', function(event) {
|
|
110
|
+
var as_sort = $(this);
|
|
111
|
+
var history_controller_id = as_sort.attr('data-page-history');
|
|
112
|
+
if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id);
|
|
113
|
+
as_sort.closest('th').addClass('loading');
|
|
114
|
+
return true;
|
|
115
|
+
});
|
|
116
|
+
$('a.as_sort').live('ajax:failure', function(event) {
|
|
117
|
+
var as_scaffold = $(this).closest('.active-scaffold');
|
|
118
|
+
ActiveScaffold.report_500_response(as_scaffold);
|
|
119
|
+
return true;
|
|
120
|
+
});
|
|
121
|
+
$('span.in_place_editor_field').live('hover', function(event) {
|
|
122
|
+
$(this).data(); // jquery 1.4.2 workaround
|
|
123
|
+
if (event.type == 'mouseenter') {
|
|
124
|
+
if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover");
|
|
125
|
+
}
|
|
126
|
+
if (event.type == 'mouseleave') {
|
|
127
|
+
if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover");
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
});
|
|
131
|
+
$('span.in_place_editor_field').live('click', function(event) {
|
|
132
|
+
var span = $(this);
|
|
133
|
+
span.data(); // jquery 1.4.2 workaround
|
|
134
|
+
if (typeof(span.data('editInPlace')) === 'undefined') {
|
|
135
|
+
var options = {show_buttons: true,
|
|
136
|
+
hover_class: 'hover',
|
|
137
|
+
element_id: 'editor_id',
|
|
138
|
+
ajax_data_type: "script",
|
|
139
|
+
update_value: 'value'},
|
|
140
|
+
csrf_param = $('meta[name=csrf-param]').first(),
|
|
141
|
+
csrf_token = $('meta[name=csrf-token]').first(),
|
|
142
|
+
my_parent = span.parent(),
|
|
143
|
+
column_heading = null;
|
|
144
|
+
|
|
145
|
+
if (my_parent.is('td')) {
|
|
146
|
+
var column_no = my_parent.prevAll('td').length;
|
|
147
|
+
column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')');
|
|
148
|
+
} else if (my_parent.is('th')) {
|
|
149
|
+
column_heading = my_parent;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
var render_url = column_heading.attr('data-ie_render_url'),
|
|
153
|
+
mode = column_heading.attr('data-ie_mode'),
|
|
154
|
+
record_id = span.attr('data-ie_id');
|
|
155
|
+
|
|
156
|
+
ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
|
|
157
|
+
|
|
158
|
+
if (span.attr('data-ie_url')) {
|
|
159
|
+
options.url = span.attr('data-ie_url').replace(/__id__/, record_id);
|
|
160
|
+
} else {
|
|
161
|
+
options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content');
|
|
165
|
+
|
|
166
|
+
if (mode === 'clone') {
|
|
167
|
+
options.clone_id_suffix = record_id;
|
|
168
|
+
options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern';
|
|
169
|
+
options.field_type = 'clone';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (render_url) {
|
|
173
|
+
var plural = false;
|
|
174
|
+
if (column_heading.attr('data-ie_plural')) plural = true;
|
|
175
|
+
options.field_type = 'remote';
|
|
176
|
+
options.editor_url = render_url.replace(/__id__/, record_id)
|
|
177
|
+
}
|
|
178
|
+
if (mode === 'inline_checkbox') {
|
|
179
|
+
ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options);
|
|
180
|
+
} else {
|
|
181
|
+
ActiveScaffold.create_inplace_editor(span, options);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
$('a.as_paginate').live('ajax:before',function(event) {
|
|
186
|
+
var as_paginate = $(this);
|
|
187
|
+
var history_controller_id = as_paginate.attr('data-page-history');
|
|
188
|
+
if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id);
|
|
189
|
+
as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
|
|
190
|
+
return true;
|
|
191
|
+
});
|
|
192
|
+
$('a.as_paginate').live('ajax:failure', function(event) {
|
|
193
|
+
var as_scaffold = $(this).closest('.active-scaffold');
|
|
194
|
+
ActiveScaffold.report_500_response(as_scaffold);
|
|
195
|
+
return true;
|
|
196
|
+
});
|
|
197
|
+
$('a.as_paginate').live('ajax:complete', function(event) {
|
|
198
|
+
$(this).prevAll('img.loading-indicator').css('visibility','hidden');
|
|
199
|
+
return true;
|
|
200
|
+
});
|
|
201
|
+
$('input[type=button].as_add_existing').live('ajax:before', function(event) {
|
|
202
|
+
var url = $(this).attr('href').replace('--ID--', $(this).prev().val());
|
|
203
|
+
event.data_url = url;
|
|
204
|
+
return true;
|
|
205
|
+
});
|
|
206
|
+
$('input.update_form, select.update_form').live('change', function(event) {
|
|
207
|
+
var element = $(this);
|
|
208
|
+
var as_form = element.closest('form.as_form');
|
|
209
|
+
$.ajax({
|
|
210
|
+
url: element.attr('data-update_url'),
|
|
211
|
+
data: {value: element.val()},
|
|
212
|
+
beforeSend: function(event) {
|
|
213
|
+
element.nextAll('img.loading-indicator').css('visibility','visible');
|
|
214
|
+
$('input[type=submit]', as_form).attr('disabled', 'disabled');
|
|
215
|
+
$("input:enabled,select:enabled", as_form).attr('disabled', 'disabled');
|
|
216
|
+
},
|
|
217
|
+
complete: function(event) {
|
|
218
|
+
element.nextAll('img.loading-indicator').css('visibility','hidden');
|
|
219
|
+
$('input[type=submit]', as_form).attr('disabled', '');
|
|
220
|
+
$("input:disabled,select:disabled", as_form).attr('disabled', '');
|
|
221
|
+
},
|
|
222
|
+
error: function (xhr, status, error) {
|
|
223
|
+
var as_div = element.closest("div.active-scaffold");
|
|
224
|
+
if (as_div) {
|
|
225
|
+
ActiveScaffold.report_500_response(as_div)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return true;
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
$('select.as_search_range_option').live('change', function(event) {
|
|
233
|
+
ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between'));
|
|
234
|
+
return true;
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
$('select.as_search_range_option').live('change', function(event) {
|
|
238
|
+
var element = $(this);
|
|
239
|
+
ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
|
|
240
|
+
ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
|
|
241
|
+
ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
|
|
242
|
+
return true;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
$('select.as_update_date_operator').live('change', function(event) {
|
|
246
|
+
ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next());
|
|
247
|
+
ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next());
|
|
248
|
+
return true;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
/* Simple Inheritance
|
|
254
|
+
http://ejohn.org/blog/simple-javascript-inheritance/
|
|
255
|
+
*/
|
|
256
|
+
(function(){
|
|
257
|
+
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
|
258
|
+
|
|
259
|
+
// The base Class implementation (does nothing)
|
|
260
|
+
this.Class = function(){};
|
|
261
|
+
|
|
262
|
+
// Create a new Class that inherits from this class
|
|
263
|
+
Class.extend = function(prop) {
|
|
264
|
+
var _super = this.prototype;
|
|
265
|
+
|
|
266
|
+
// Instantiate a base class (but only create the instance,
|
|
267
|
+
// don't run the init constructor)
|
|
268
|
+
initializing = true;
|
|
269
|
+
var prototype = new this();
|
|
270
|
+
initializing = false;
|
|
271
|
+
|
|
272
|
+
// Copy the properties over onto the new prototype
|
|
273
|
+
for (var name in prop) {
|
|
274
|
+
// Check if we're overwriting an existing function
|
|
275
|
+
prototype[name] = typeof prop[name] == "function" &&
|
|
276
|
+
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
|
277
|
+
(function(name, fn){
|
|
278
|
+
return function() {
|
|
279
|
+
var tmp = this._super;
|
|
280
|
+
|
|
281
|
+
// Add a new ._super() method that is the same method
|
|
282
|
+
// but on the super-class
|
|
283
|
+
this._super = _super[name];
|
|
284
|
+
|
|
285
|
+
// The method only need to be bound temporarily, so we
|
|
286
|
+
// remove it when we're done executing
|
|
287
|
+
var ret = fn.apply(this, arguments);
|
|
288
|
+
this._super = tmp;
|
|
289
|
+
|
|
290
|
+
return ret;
|
|
291
|
+
};
|
|
292
|
+
})(name, prop[name]) :
|
|
293
|
+
prop[name];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// The dummy class constructor
|
|
297
|
+
function Class() {
|
|
298
|
+
// All construction is actually done in the init method
|
|
299
|
+
if ( !initializing && this.init )
|
|
300
|
+
this.init.apply(this, arguments);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Populate our constructed prototype object
|
|
304
|
+
Class.prototype = prototype;
|
|
305
|
+
|
|
306
|
+
// Enforce the constructor to be what we expect
|
|
307
|
+
Class.constructor = Class;
|
|
308
|
+
|
|
309
|
+
// And make this class extendable
|
|
310
|
+
Class.extend = arguments.callee;
|
|
311
|
+
|
|
312
|
+
return Class;
|
|
313
|
+
};
|
|
314
|
+
})();
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
jQuery delayed observer
|
|
318
|
+
(c) 2007 - Maxime Haineault (max@centdessin.com)
|
|
319
|
+
|
|
320
|
+
Special thanks to Stephen Goguen & Tane Piper.
|
|
321
|
+
|
|
322
|
+
Slight modifications by Elliot Winkler
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
|
|
326
|
+
(function() {
|
|
327
|
+
var delayedObserverStack = [];
|
|
328
|
+
var observed;
|
|
329
|
+
|
|
330
|
+
function delayedObserverCallback(stackPos) {
|
|
331
|
+
observed = delayedObserverStack[stackPos];
|
|
332
|
+
if (observed.timer) return;
|
|
333
|
+
|
|
334
|
+
observed.timer = setTimeout(function(){
|
|
335
|
+
observed.timer = null;
|
|
336
|
+
observed.callback(observed.obj.val(), observed.obj);
|
|
337
|
+
}, observed.delay * 1000);
|
|
338
|
+
|
|
339
|
+
observed.oldVal = observed.obj.val();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// going by
|
|
343
|
+
// <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx>
|
|
344
|
+
// I think these codes only work when using keyup or keydown
|
|
345
|
+
function isNonPrintableKey(event) {
|
|
346
|
+
var code = event.keyCode;
|
|
347
|
+
return (
|
|
348
|
+
event.metaKey ||
|
|
349
|
+
(code >= 9 && code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145)
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
jQuery.fn.extend({
|
|
354
|
+
delayedObserver:function(delay, callback){
|
|
355
|
+
$this = $(this);
|
|
356
|
+
|
|
357
|
+
delayedObserverStack.push({
|
|
358
|
+
obj: $this, timer: null, delay: delay,
|
|
359
|
+
oldVal: $this.val(), callback: callback
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
stackPos = delayedObserverStack.length-1;
|
|
363
|
+
|
|
364
|
+
$this.keyup(function(event) {
|
|
365
|
+
if (isNonPrintableKey(event)) return;
|
|
366
|
+
observed = delayedObserverStack[stackPos];
|
|
367
|
+
if (observed.obj.val() == observed.obj.oldVal) return;
|
|
368
|
+
else delayedObserverCallback(stackPos);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
})();
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
/*
|
|
377
|
+
* Simple utility methods
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
var ActiveScaffold = {
|
|
381
|
+
records_for: function(tbody_id) {
|
|
382
|
+
if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id;
|
|
383
|
+
return $(tbody_id).children('.record');
|
|
384
|
+
},
|
|
385
|
+
stripe: function(tbody_id) {
|
|
386
|
+
var even = false;
|
|
387
|
+
var rows = this.records_for(tbody_id);
|
|
388
|
+
|
|
389
|
+
rows.each(function (index, row_node) {
|
|
390
|
+
row = $(row_node);
|
|
391
|
+
if (row_node.tagName != 'SCRIPT'
|
|
392
|
+
&& !row.hasClass("create")
|
|
393
|
+
&& !row.hasClass("update")
|
|
394
|
+
&& !row.hasClass("inline-adapter")
|
|
395
|
+
&& !row.hasClass("active-scaffold-calculations")) {
|
|
396
|
+
|
|
397
|
+
if (even) row.addClass("even-record");
|
|
398
|
+
else row.removeClass("even-record");
|
|
399
|
+
|
|
400
|
+
even = !even;
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
},
|
|
404
|
+
hide_empty_message: function(tbody) {
|
|
405
|
+
if (this.records_for(tbody).length != 0) {
|
|
406
|
+
var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message')
|
|
407
|
+
if (empty_message_node) empty_message_node.hide();
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
reload_if_empty: function(tbody, url) {
|
|
411
|
+
if (this.records_for(tbody).length == 0) {
|
|
412
|
+
$.getScript(url);
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
removeSortClasses: function(scaffold) {
|
|
416
|
+
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
|
417
|
+
scaffold = $(scaffold)
|
|
418
|
+
scaffold.find('td.sorted').each(function(element) {
|
|
419
|
+
element.removeClass("sorted");
|
|
420
|
+
});
|
|
421
|
+
scaffold.find('th.sorted').each(function(element) {
|
|
422
|
+
element.removeClass("sorted");
|
|
423
|
+
element.removeClass("asc");
|
|
424
|
+
element.removeClass("desc");
|
|
425
|
+
});
|
|
426
|
+
},
|
|
427
|
+
decrement_record_count: function(scaffold) {
|
|
428
|
+
// decrement the last record count, firsts record count are in nested lists
|
|
429
|
+
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
|
430
|
+
scaffold = $(scaffold)
|
|
431
|
+
count = scaffold.find('span.active-scaffold-records').last();
|
|
432
|
+
if (count) count.html(parseInt(count.html(), 10) - 1);
|
|
433
|
+
},
|
|
434
|
+
increment_record_count: function(scaffold) {
|
|
435
|
+
// increment the last record count, firsts record count are in nested lists
|
|
436
|
+
if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
|
|
437
|
+
scaffold = $(scaffold)
|
|
438
|
+
count = scaffold.find('span.active-scaffold-records').last();
|
|
439
|
+
if (count) count.html(parseInt(count.html(), 10) + 1);
|
|
440
|
+
},
|
|
441
|
+
update_row: function(row, html) {
|
|
442
|
+
var even_row = false;
|
|
443
|
+
var replaced = null;
|
|
444
|
+
if (typeof(row) == 'string') row = '#' + row;
|
|
445
|
+
row = $(row);
|
|
446
|
+
if (row.hasClass('even-record')) even_row = true;
|
|
447
|
+
|
|
448
|
+
replaced = this.replace(row, html);
|
|
449
|
+
if (even_row === true) replaced.addClass('even-record');
|
|
450
|
+
ActiveScaffold.highlight(replaced);
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
replace: function(element, html) {
|
|
454
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
455
|
+
element = $(element);
|
|
456
|
+
element.replaceWith(html);
|
|
457
|
+
if (element.attr('id')) {
|
|
458
|
+
element = $('#' + element.attr('id'));
|
|
459
|
+
}
|
|
460
|
+
return element;
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
replace_html: function(element, html) {
|
|
464
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
465
|
+
element = $(element);
|
|
466
|
+
element.html(html);
|
|
467
|
+
return element;
|
|
468
|
+
},
|
|
469
|
+
|
|
470
|
+
remove: function(element) {
|
|
471
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
472
|
+
$(element).remove();
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
hide: function(element) {
|
|
476
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
477
|
+
$(element).hide();
|
|
478
|
+
},
|
|
479
|
+
|
|
480
|
+
show: function(element) {
|
|
481
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
482
|
+
$(element).show();
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
reset_form: function(element) {
|
|
486
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
487
|
+
$(element).get(0).reset();
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
disable_form: function(as_form) {
|
|
491
|
+
if (typeof(as_form) == 'string') as_form = '#' + as_form;
|
|
492
|
+
as_form = $(as_form)
|
|
493
|
+
var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
|
|
494
|
+
if (loading_indicator) loading_indicator.css('visibility','visible');
|
|
495
|
+
$('input[type=submit]', as_form).attr('disabled', 'disabled');
|
|
496
|
+
$("input:enabled,select:enabled", as_form).attr('disabled', 'disabled');
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
enable_form: function(as_form) {
|
|
500
|
+
if (typeof(as_form) == 'string') as_form = '#' + as_form;
|
|
501
|
+
as_form = $(as_form)
|
|
502
|
+
var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
|
|
503
|
+
if (loading_indicator) loading_indicator.css('visibility','hidden');
|
|
504
|
+
$('input[type=submit]', as_form).attr('disabled', '');
|
|
505
|
+
$("input:disabled,select:disabled", as_form).attr('disabled', '');
|
|
506
|
+
},
|
|
507
|
+
|
|
508
|
+
focus_first_element_of_form: function(form_element) {
|
|
509
|
+
if (typeof(form_element) == 'string') form_element = '#' + form_element;
|
|
510
|
+
$(form_element + ":first *:input[type!=hidden]:first").focus();
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
create_record_row: function(tbody, html, options) {
|
|
514
|
+
if (typeof(tbody) == 'string') tbody = '#' + tbody;
|
|
515
|
+
tbody = $(tbody);
|
|
516
|
+
|
|
517
|
+
if (options.insert_at == 'top') {
|
|
518
|
+
tbody.prepend(html);
|
|
519
|
+
var new_row = tbody.children('tr.record:first-child');
|
|
520
|
+
} else if (options.insert_at == 'bottom') {
|
|
521
|
+
var rows = tbody.children('tr.record, tr.inline-adapter');
|
|
522
|
+
var new_row = null;
|
|
523
|
+
if (rows.length > 0) {
|
|
524
|
+
new_row = rows.last().after(html).next();
|
|
525
|
+
} else {
|
|
526
|
+
new_row = tbody.append(html).children().last();
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
this.stripe(tbody);
|
|
530
|
+
this.hide_empty_message(tbody);
|
|
531
|
+
this.increment_record_count(tbody.closest('div.active-scaffold'));
|
|
532
|
+
ActiveScaffold.highlight(new_row);
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
delete_record_row: function(row, page_reload_url) {
|
|
536
|
+
if (typeof(row) == 'string') row = '#' + row;
|
|
537
|
+
row = $(row);
|
|
538
|
+
var tbody = row.closest('tbody.records');
|
|
539
|
+
|
|
540
|
+
var current_action_node = row.find('td.actions a.disabled').first();
|
|
541
|
+
if (current_action_node) {
|
|
542
|
+
var action_link = ActiveScaffold.ActionLink.get(current_action_node);
|
|
543
|
+
if (action_link) {
|
|
544
|
+
action_link.close_previous_adapter();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
row.remove();
|
|
549
|
+
this.stripe(tbody);
|
|
550
|
+
this.decrement_record_count(tbody.closest('div.active-scaffold'));
|
|
551
|
+
this.reload_if_empty(tbody, page_reload_url);
|
|
552
|
+
},
|
|
553
|
+
|
|
554
|
+
report_500_response: function(active_scaffold_id) {
|
|
555
|
+
server_error = $(active_scaffold_id).find('td.messages-container p.server-error');
|
|
556
|
+
if (!$(server_error).is(':visible')) {
|
|
557
|
+
server_error.show();
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
|
|
561
|
+
find_action_link: function(element) {
|
|
562
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
563
|
+
var as_adapter = $(element).closest('.as_adapter');
|
|
564
|
+
return ActiveScaffold.ActionLink.get(as_adapter);
|
|
565
|
+
},
|
|
566
|
+
|
|
567
|
+
scroll_to: function(element) {
|
|
568
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
569
|
+
var form_offset = $(element).offset(),
|
|
570
|
+
destination = form_offset.top;
|
|
571
|
+
$(document).scrollTop(destination);
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
process_checkbox_inplace_edit: function(checkbox, options) {
|
|
575
|
+
var checked = checkbox.is(':checked');
|
|
576
|
+
if (checked === true) options['params'] += '&value=1';
|
|
577
|
+
$.ajax({
|
|
578
|
+
url: options.url,
|
|
579
|
+
type: "POST",
|
|
580
|
+
data: options['params'],
|
|
581
|
+
dataType: options.ajax_data_type,
|
|
582
|
+
after: function(request){
|
|
583
|
+
checkbox.attr('disabled', 'disabled');
|
|
584
|
+
},
|
|
585
|
+
complete: function(request){
|
|
586
|
+
checkbox.attr('disabled', '');
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
},
|
|
590
|
+
|
|
591
|
+
read_inplace_edit_heading_attributes: function(column_heading, options) {
|
|
592
|
+
if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>";
|
|
593
|
+
if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text');
|
|
594
|
+
if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text');
|
|
595
|
+
if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>";
|
|
596
|
+
if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows');
|
|
597
|
+
if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols');
|
|
598
|
+
if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size');
|
|
599
|
+
},
|
|
600
|
+
|
|
601
|
+
create_inplace_editor: function(span, options) {
|
|
602
|
+
span.removeClass('hover');
|
|
603
|
+
span.editInPlace(options);
|
|
604
|
+
span.trigger('click.editInPlace');
|
|
605
|
+
},
|
|
606
|
+
|
|
607
|
+
highlight: function(element) {
|
|
608
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
609
|
+
if (typeof(element.effect) == 'function') {
|
|
610
|
+
element.effect("highlight", {}, 3000);
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
|
|
614
|
+
create_visibility_toggle: function(element, options) {
|
|
615
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
616
|
+
var toggable = $(element);
|
|
617
|
+
var toggler = toggable.prev();
|
|
618
|
+
var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label;
|
|
619
|
+
|
|
620
|
+
toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)');
|
|
621
|
+
toggler.children('a').click(function() {
|
|
622
|
+
toggable.toggle();
|
|
623
|
+
$(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label);
|
|
624
|
+
});
|
|
625
|
+
},
|
|
626
|
+
|
|
627
|
+
create_associated_record_form: function(element, content, options) {
|
|
628
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
629
|
+
var element = $(element);
|
|
630
|
+
if (options.singular == false) {
|
|
631
|
+
if (!(options.id && $('#' + options.id).size() > 0)) {
|
|
632
|
+
element.append(content);
|
|
633
|
+
}
|
|
634
|
+
} else {
|
|
635
|
+
if (current = $('#' + element.attr('id') + ' tr.association-record')[0]) {
|
|
636
|
+
this.replace(current, content);
|
|
637
|
+
} else {
|
|
638
|
+
element.prepend(content);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
|
|
643
|
+
render_form_field: function(element, content, options) {
|
|
644
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
645
|
+
var element = $(element);
|
|
646
|
+
if (options.is_subform == false) {
|
|
647
|
+
this.replace(element.closest('dl'), content);
|
|
648
|
+
} else {
|
|
649
|
+
this.replace_html(element, content);
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
|
|
653
|
+
sortable: function(element, controller, options, url_params) {
|
|
654
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
655
|
+
var element = $(element);
|
|
656
|
+
var sortable_options = {};
|
|
657
|
+
if (options.update === true) {
|
|
658
|
+
url_params.authenticity_token = $('meta[name=csrf-param]').attr('content');
|
|
659
|
+
sortable_options.update = function(event, ui) {
|
|
660
|
+
var url = controller + '/' + options.action + '?'
|
|
661
|
+
url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/});
|
|
662
|
+
$.post(url.append_params(url_params));
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
element.sortable(sortable_options);
|
|
666
|
+
},
|
|
667
|
+
|
|
668
|
+
record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
|
|
669
|
+
$.ajax({
|
|
670
|
+
url: edit_associated_url.split('--ID--').join(id),
|
|
671
|
+
error: function(xhr, textStatus, errorThrown){
|
|
672
|
+
ActiveScaffold.report_500_response(active_scaffold_id)
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/*
|
|
679
|
+
* DHTML history tie-in
|
|
680
|
+
*/
|
|
681
|
+
function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
|
|
682
|
+
if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
|
|
683
|
+
|
|
684
|
+
var array = url.split('?');
|
|
685
|
+
var qs = new Querystring(array[1]);
|
|
686
|
+
var sort = qs.get('sort')
|
|
687
|
+
var dir = qs.get('sort_direction')
|
|
688
|
+
var page = qs.get('page')
|
|
689
|
+
if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/*
|
|
693
|
+
* URL modification support. Incomplete functionality.
|
|
694
|
+
*/
|
|
695
|
+
String.prototype.append_params = function(params) {
|
|
696
|
+
var url = this;
|
|
697
|
+
if (url.indexOf('?') == -1) url += '?';
|
|
698
|
+
else if (url.lastIndexOf('&') != url.length) url += '&';
|
|
699
|
+
|
|
700
|
+
for(var key in params) {
|
|
701
|
+
if (key) url += (key + '=' + params[key] + '&');
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// the loop leaves a comma dangling at the end of string, chop it off
|
|
705
|
+
url = url.substring(0, url.length-1);
|
|
706
|
+
return url;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
|
|
712
|
+
*/
|
|
713
|
+
ActiveScaffold.Actions = new Object();
|
|
714
|
+
ActiveScaffold.Actions.Abstract = Class.extend({
|
|
715
|
+
init: function(links, target, loading_indicator, options) {
|
|
716
|
+
this.target = $(target);
|
|
717
|
+
this.loading_indicator = $(loading_indicator);
|
|
718
|
+
this.options = options;
|
|
719
|
+
var _this = this;
|
|
720
|
+
this.links = $.map(links, function(link) {
|
|
721
|
+
var my_link = _this.instantiate_link(link);
|
|
722
|
+
return my_link;
|
|
723
|
+
});
|
|
724
|
+
},
|
|
725
|
+
|
|
726
|
+
instantiate_link: function(link) {
|
|
727
|
+
throw 'unimplemented'
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* A DataStructures::ActionLink, represented in JavaScript.
|
|
733
|
+
* Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
|
|
734
|
+
*/
|
|
735
|
+
ActiveScaffold.ActionLink = {
|
|
736
|
+
get: function(element) {
|
|
737
|
+
if (typeof(element) == 'string') element = '#' + element;
|
|
738
|
+
var element = $(element);
|
|
739
|
+
if (element.length > 0) {
|
|
740
|
+
element.data(); // jquery 1.4.2 workaround
|
|
741
|
+
if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
|
|
742
|
+
var parent = element.parent();
|
|
743
|
+
|
|
744
|
+
if (parent && parent.is('td')) {
|
|
745
|
+
// record action
|
|
746
|
+
parent = parent.closest('tr.record');
|
|
747
|
+
var target = parent.find('a.as_action');
|
|
748
|
+
var loading_indicator = parent.find('td.actions .loading-indicator');
|
|
749
|
+
new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
|
|
750
|
+
} else if (parent && parent.is('div')) {
|
|
751
|
+
//table action
|
|
752
|
+
new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator'));
|
|
753
|
+
}
|
|
754
|
+
element = $(element);
|
|
755
|
+
}
|
|
756
|
+
return element.data('action_link');
|
|
757
|
+
} else {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
ActiveScaffold.ActionLink.Abstract = Class.extend({
|
|
763
|
+
init: function(a, target, loading_indicator) {
|
|
764
|
+
this.tag = $(a);
|
|
765
|
+
this.url = this.tag.attr('href');
|
|
766
|
+
this.method = 'get';
|
|
767
|
+
|
|
768
|
+
if(this.url.match('_method=delete')){
|
|
769
|
+
this.method = 'delete';
|
|
770
|
+
// action delete is special case cause in ajax world it will be destroy
|
|
771
|
+
} else if(this.url.match('/delete')){
|
|
772
|
+
this.url = this.url.replace('/delete', '');
|
|
773
|
+
this.tag.attr('href', this.url);
|
|
774
|
+
this.method = 'delete';
|
|
775
|
+
} else if(this.url.match('_method=post')){
|
|
776
|
+
this.method = 'post';
|
|
777
|
+
} else if(this.url.match('_method=put')){
|
|
778
|
+
this.method = 'put';
|
|
779
|
+
}
|
|
780
|
+
if (this.method != 'get') this.tag.attr('data-method', this.method);
|
|
781
|
+
this.target = target;
|
|
782
|
+
this.loading_indicator = loading_indicator;
|
|
783
|
+
this.hide_target = false;
|
|
784
|
+
this.position = this.tag.attr('data-position');
|
|
785
|
+
|
|
786
|
+
this.tag.data('action_link', this);
|
|
787
|
+
return this;
|
|
788
|
+
},
|
|
789
|
+
|
|
790
|
+
open: function(event) {
|
|
791
|
+
},
|
|
792
|
+
|
|
793
|
+
insert: function(content) {
|
|
794
|
+
throw 'unimplemented'
|
|
795
|
+
},
|
|
796
|
+
|
|
797
|
+
close: function() {
|
|
798
|
+
this.enable();
|
|
799
|
+
this.adapter.remove();
|
|
800
|
+
if (this.hide_target) this.target.show();
|
|
801
|
+
},
|
|
802
|
+
|
|
803
|
+
reload: function() {
|
|
804
|
+
this.close();
|
|
805
|
+
this.open();
|
|
806
|
+
},
|
|
807
|
+
|
|
808
|
+
get_new_adapter_id: function() {
|
|
809
|
+
var id = 'adapter_';
|
|
810
|
+
var i = 0;
|
|
811
|
+
while ($(id + i)) i++;
|
|
812
|
+
return id + i;
|
|
813
|
+
},
|
|
814
|
+
|
|
815
|
+
enable: function() {
|
|
816
|
+
return this.tag.removeClass('disabled');
|
|
817
|
+
},
|
|
818
|
+
|
|
819
|
+
disable: function() {
|
|
820
|
+
return this.tag.addClass('disabled');
|
|
821
|
+
},
|
|
822
|
+
|
|
823
|
+
is_disabled: function() {
|
|
824
|
+
return this.tag.hasClass('disabled');
|
|
825
|
+
},
|
|
826
|
+
|
|
827
|
+
scaffold_id: function() {
|
|
828
|
+
return '#' + this.tag.closest('div.active-scaffold').attr('id');
|
|
829
|
+
},
|
|
830
|
+
|
|
831
|
+
update_flash_messages: function(messages) {
|
|
832
|
+
message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages'));
|
|
833
|
+
if (message_node) message_node.html(messages);
|
|
834
|
+
},
|
|
835
|
+
set_adapter: function(element) {
|
|
836
|
+
this.adapter = element;
|
|
837
|
+
this.adapter.addClass('as_adapter');
|
|
838
|
+
this.adapter.data('action_link', this);
|
|
839
|
+
},
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Concrete classes for record actions
|
|
844
|
+
*/
|
|
845
|
+
ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
|
|
846
|
+
instantiate_link: function(link) {
|
|
847
|
+
var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
|
|
848
|
+
var refresh = this.target.attr('data-refresh');
|
|
849
|
+
if (refresh) l.refresh_url = refresh;
|
|
850
|
+
|
|
851
|
+
if ($(link).hasClass('delete')) {
|
|
852
|
+
l.url = l.url.replace(/\/delete(\?.*)?$/, '$1');
|
|
853
|
+
l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1');
|
|
854
|
+
l.tag.attr('href', l.url);
|
|
855
|
+
}
|
|
856
|
+
if (l.position) {
|
|
857
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
|
858
|
+
l.tag.attr('href', l.url);
|
|
859
|
+
}
|
|
860
|
+
l.set = this;
|
|
861
|
+
return l;
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
|
|
866
|
+
close_previous_adapter: function() {
|
|
867
|
+
var _this = this;
|
|
868
|
+
$.each(this.set.links, function(index, item) {
|
|
869
|
+
if (item.url != _this.url && item.is_disabled() && item.adapter) {
|
|
870
|
+
item.enable();
|
|
871
|
+
item.adapter.remove();
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
},
|
|
875
|
+
|
|
876
|
+
insert: function(content) {
|
|
877
|
+
this.close_previous_adapter();
|
|
878
|
+
|
|
879
|
+
if (this.position == 'replace') {
|
|
880
|
+
this.position = 'after';
|
|
881
|
+
this.hide_target = true;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
if (this.position == 'after') {
|
|
885
|
+
this.target.after(content);
|
|
886
|
+
this.set_adapter(this.target.next());
|
|
887
|
+
}
|
|
888
|
+
else if (this.position == 'before') {
|
|
889
|
+
this.target.before(content);
|
|
890
|
+
this.set_adapter(this.target.prev());
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
return false;
|
|
894
|
+
}
|
|
895
|
+
ActiveScaffold.highlight(this.adapter.find('td'));
|
|
896
|
+
},
|
|
897
|
+
|
|
898
|
+
close: function(refreshed_content) {
|
|
899
|
+
if (refreshed_content) {
|
|
900
|
+
ActiveScaffold.update_row(this.target, refreshed_content);
|
|
901
|
+
}
|
|
902
|
+
this._super();
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
enable: function() {
|
|
906
|
+
var _this = this;
|
|
907
|
+
$.each(this.set.links, function(index, item) {
|
|
908
|
+
if (item.url != _this.url) return;
|
|
909
|
+
item.tag.removeClass('disabled');
|
|
910
|
+
});
|
|
911
|
+
},
|
|
912
|
+
|
|
913
|
+
disable: function() {
|
|
914
|
+
var _this = this;
|
|
915
|
+
$.each(this.set.links, function(index, item) {
|
|
916
|
+
if (item.url != _this.url) return;
|
|
917
|
+
item.tag.addClass('disabled');
|
|
918
|
+
});
|
|
919
|
+
},
|
|
920
|
+
|
|
921
|
+
set_opened: function() {
|
|
922
|
+
if (this.position == 'after') {
|
|
923
|
+
this.set_adapter(this.target.next());
|
|
924
|
+
}
|
|
925
|
+
else if (this.position == 'before') {
|
|
926
|
+
this.set_adapter(this.target.prev());
|
|
927
|
+
}
|
|
928
|
+
this.disable();
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Concrete classes for table actions
|
|
934
|
+
*/
|
|
935
|
+
ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
|
|
936
|
+
instantiate_link: function(link) {
|
|
937
|
+
var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
|
|
938
|
+
if (l.position) {
|
|
939
|
+
l.url = l.url.append_params({adapter: '_list_inline_adapter'});
|
|
940
|
+
l.tag.attr('href', l.url);
|
|
941
|
+
}
|
|
942
|
+
return l;
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
|
|
947
|
+
insert: function(content) {
|
|
948
|
+
if (this.position == 'top') {
|
|
949
|
+
this.target.prepend(content);
|
|
950
|
+
this.set_adapter(this.target.children().first());
|
|
951
|
+
}
|
|
952
|
+
else {
|
|
953
|
+
throw 'Unknown position "' + this.position + '"'
|
|
954
|
+
}
|
|
955
|
+
ActiveScaffold.highlight(this.adapter.find('td').first().children());
|
|
956
|
+
}
|
|
957
|
+
});
|