active_scaffold_san 3.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. data/.autotest +27 -0
  2. data/.document +5 -0
  3. data/CHANGELOG +179 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +20 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README +69 -0
  8. data/Rakefile +53 -0
  9. data/active_scaffold_vho.gemspec +388 -0
  10. data/frontends/default/images/add.gif +0 -0
  11. data/frontends/default/images/arrow_down.gif +0 -0
  12. data/frontends/default/images/arrow_up.gif +0 -0
  13. data/frontends/default/images/close.gif +0 -0
  14. data/frontends/default/images/config.png +0 -0
  15. data/frontends/default/images/cross.png +0 -0
  16. data/frontends/default/images/gears.png +0 -0
  17. data/frontends/default/images/indicator-small.gif +0 -0
  18. data/frontends/default/images/indicator.gif +0 -0
  19. data/frontends/default/images/magnifier.png +0 -0
  20. data/frontends/default/javascripts/jquery/active_scaffold.js +1004 -0
  21. data/frontends/default/javascripts/jquery/jquery.editinplace.js +743 -0
  22. data/frontends/default/javascripts/prototype/active_scaffold.js +1003 -0
  23. data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
  24. data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
  25. data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
  26. data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
  27. data/frontends/default/stylesheets/stylesheet.css +973 -0
  28. data/frontends/default/views/_action_group.html.erb +20 -0
  29. data/frontends/default/views/_add_existing_form.html.erb +30 -0
  30. data/frontends/default/views/_base_form.html.erb +51 -0
  31. data/frontends/default/views/_create_form.html.erb +8 -0
  32. data/frontends/default/views/_create_form_on_list.html.erb +6 -0
  33. data/frontends/default/views/_field_search.html.erb +32 -0
  34. data/frontends/default/views/_form.html.erb +24 -0
  35. data/frontends/default/views/_form_association.html.erb +19 -0
  36. data/frontends/default/views/_form_association_footer.html.erb +40 -0
  37. data/frontends/default/views/_form_attribute.html.erb +15 -0
  38. data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
  39. data/frontends/default/views/_form_messages.html.erb +5 -0
  40. data/frontends/default/views/_horizontal_subform.html.erb +29 -0
  41. data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
  42. data/frontends/default/views/_horizontal_subform_record.html.erb +37 -0
  43. data/frontends/default/views/_human_conditions.html.erb +1 -0
  44. data/frontends/default/views/_list.html.erb +18 -0
  45. data/frontends/default/views/_list_actions.html.erb +15 -0
  46. data/frontends/default/views/_list_calculations.html.erb +16 -0
  47. data/frontends/default/views/_list_column_headings.html.erb +12 -0
  48. data/frontends/default/views/_list_header.html.erb +10 -0
  49. data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
  50. data/frontends/default/views/_list_messages.html.erb +32 -0
  51. data/frontends/default/views/_list_pagination.html.erb +11 -0
  52. data/frontends/default/views/_list_pagination_links.html.erb +9 -0
  53. data/frontends/default/views/_list_record.html.erb +14 -0
  54. data/frontends/default/views/_list_record_columns.html.erb +8 -0
  55. data/frontends/default/views/_list_with_header.html.erb +32 -0
  56. data/frontends/default/views/_messages.html.erb +10 -0
  57. data/frontends/default/views/_render_field.js.rjs +10 -0
  58. data/frontends/default/views/_row.html.erb +12 -0
  59. data/frontends/default/views/_search.html.erb +34 -0
  60. data/frontends/default/views/_search_attribute.html.erb +10 -0
  61. data/frontends/default/views/_show.html.erb +8 -0
  62. data/frontends/default/views/_show_columns.html.erb +15 -0
  63. data/frontends/default/views/_update_actions.html.erb +9 -0
  64. data/frontends/default/views/_update_form.html.erb +6 -0
  65. data/frontends/default/views/_vertical_subform.html.erb +12 -0
  66. data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
  67. data/frontends/default/views/action_confirmation.html.erb +13 -0
  68. data/frontends/default/views/add_existing.js.rjs +17 -0
  69. data/frontends/default/views/add_existing_form.html.erb +5 -0
  70. data/frontends/default/views/create.html.erb +5 -0
  71. data/frontends/default/views/delete.html.erb +13 -0
  72. data/frontends/default/views/destroy.js.rjs +23 -0
  73. data/frontends/default/views/edit_associated.js.rjs +11 -0
  74. data/frontends/default/views/field_search.html.erb +5 -0
  75. data/frontends/default/views/form_messages.js.rjs +1 -0
  76. data/frontends/default/views/list.html.erb +1 -0
  77. data/frontends/default/views/list.js.rjs +1 -0
  78. data/frontends/default/views/on_action_update.js.rjs +8 -0
  79. data/frontends/default/views/on_create.js.rjs +41 -0
  80. data/frontends/default/views/on_mark_all.js.rjs +4 -0
  81. data/frontends/default/views/on_update.js.rjs +28 -0
  82. data/frontends/default/views/search.html.erb +5 -0
  83. data/frontends/default/views/show.html.erb +5 -0
  84. data/frontends/default/views/update.html.erb +8 -0
  85. data/frontends/default/views/update_column.js.rjs +13 -0
  86. data/frontends/default/views/update_row.js.rjs +1 -0
  87. data/init.rb +8 -0
  88. data/lib/active_scaffold.rb +360 -0
  89. data/lib/active_scaffold/actions/common_search.rb +22 -0
  90. data/lib/active_scaffold/actions/core.rb +180 -0
  91. data/lib/active_scaffold/actions/create.rb +149 -0
  92. data/lib/active_scaffold/actions/delete.rb +75 -0
  93. data/lib/active_scaffold/actions/field_search.rb +82 -0
  94. data/lib/active_scaffold/actions/list.rb +184 -0
  95. data/lib/active_scaffold/actions/mark.rb +63 -0
  96. data/lib/active_scaffold/actions/nested.rb +250 -0
  97. data/lib/active_scaffold/actions/search.rb +47 -0
  98. data/lib/active_scaffold/actions/show.rb +61 -0
  99. data/lib/active_scaffold/actions/subform.rb +27 -0
  100. data/lib/active_scaffold/actions/update.rb +151 -0
  101. data/lib/active_scaffold/active_record_permissions.rb +134 -0
  102. data/lib/active_scaffold/attribute_params.rb +211 -0
  103. data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
  104. data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +39 -0
  105. data/lib/active_scaffold/bridges/bridge.rb +59 -0
  106. data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
  107. data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +83 -0
  108. data/lib/active_scaffold/bridges/cancan/bridge.rb +12 -0
  109. data/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +107 -0
  110. data/lib/active_scaffold/bridges/carrierwave/bridge.rb +9 -0
  111. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +33 -0
  112. data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +12 -0
  113. data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +45 -0
  114. data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
  115. data/lib/active_scaffold/bridges/date_picker/bridge.rb +24 -0
  116. data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
  117. data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
  118. data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
  119. data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
  120. data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
  121. data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
  122. data/lib/active_scaffold/bridges/file_column/lib/list_ui.rb +26 -0
  123. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
  124. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
  125. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
  126. data/lib/active_scaffold/bridges/paperclip/bridge.rb +12 -0
  127. data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
  128. data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
  129. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
  130. data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
  131. data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
  132. data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
  133. data/lib/active_scaffold/bridges/shared/date_bridge.rb +209 -0
  134. data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
  135. data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +61 -0
  136. data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
  137. data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
  138. data/lib/active_scaffold/config/base.rb +62 -0
  139. data/lib/active_scaffold/config/core.rb +220 -0
  140. data/lib/active_scaffold/config/create.rb +51 -0
  141. data/lib/active_scaffold/config/delete.rb +34 -0
  142. data/lib/active_scaffold/config/field_search.rb +75 -0
  143. data/lib/active_scaffold/config/form.rb +47 -0
  144. data/lib/active_scaffold/config/list.rb +174 -0
  145. data/lib/active_scaffold/config/mark.rb +22 -0
  146. data/lib/active_scaffold/config/nested.rb +44 -0
  147. data/lib/active_scaffold/config/search.rb +69 -0
  148. data/lib/active_scaffold/config/show.rb +35 -0
  149. data/lib/active_scaffold/config/subform.rb +35 -0
  150. data/lib/active_scaffold/config/update.rb +46 -0
  151. data/lib/active_scaffold/configurable.rb +29 -0
  152. data/lib/active_scaffold/constraints.rb +184 -0
  153. data/lib/active_scaffold/data_structures/action_columns.rb +137 -0
  154. data/lib/active_scaffold/data_structures/action_link.rb +175 -0
  155. data/lib/active_scaffold/data_structures/action_links.rb +185 -0
  156. data/lib/active_scaffold/data_structures/actions.rb +45 -0
  157. data/lib/active_scaffold/data_structures/column.rb +355 -0
  158. data/lib/active_scaffold/data_structures/columns.rb +75 -0
  159. data/lib/active_scaffold/data_structures/error_message.rb +24 -0
  160. data/lib/active_scaffold/data_structures/nested_info.rb +123 -0
  161. data/lib/active_scaffold/data_structures/set.rb +62 -0
  162. data/lib/active_scaffold/data_structures/sorting.rb +168 -0
  163. data/lib/active_scaffold/extensions/action_controller_rendering.rb +20 -0
  164. data/lib/active_scaffold/extensions/action_view_rendering.rb +123 -0
  165. data/lib/active_scaffold/extensions/action_view_resolver.rb +7 -0
  166. data/lib/active_scaffold/extensions/active_association_reflection.rb +13 -0
  167. data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
  168. data/lib/active_scaffold/extensions/array.rb +7 -0
  169. data/lib/active_scaffold/extensions/localize.rb +10 -0
  170. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
  171. data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
  172. data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
  173. data/lib/active_scaffold/extensions/reverse_associations.rb +62 -0
  174. data/lib/active_scaffold/extensions/routing_mapper.rb +34 -0
  175. data/lib/active_scaffold/extensions/to_label.rb +8 -0
  176. data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
  177. data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
  178. data/lib/active_scaffold/extensions/usa_state.rb +46 -0
  179. data/lib/active_scaffold/finder.rb +343 -0
  180. data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
  181. data/lib/active_scaffold/helpers/controller_helpers.rb +87 -0
  182. data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
  183. data/lib/active_scaffold/helpers/form_column_helpers.rb +350 -0
  184. data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
  185. data/lib/active_scaffold/helpers/id_helpers.rb +127 -0
  186. data/lib/active_scaffold/helpers/list_column_helpers.rb +361 -0
  187. data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
  188. data/lib/active_scaffold/helpers/search_column_helpers.rb +249 -0
  189. data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
  190. data/lib/active_scaffold/helpers/view_helpers.rb +360 -0
  191. data/lib/active_scaffold/locale/de.rb +120 -0
  192. data/lib/active_scaffold/locale/en.rb +119 -0
  193. data/lib/active_scaffold/locale/es.yml +115 -0
  194. data/lib/active_scaffold/locale/fr.rb +122 -0
  195. data/lib/active_scaffold/locale/hu.yml +63 -0
  196. data/lib/active_scaffold/locale/ja.yml +64 -0
  197. data/lib/active_scaffold/locale/ru.yml +119 -0
  198. data/lib/active_scaffold/marked_model.rb +38 -0
  199. data/lib/active_scaffold/paginator.rb +136 -0
  200. data/lib/active_scaffold/responds_to_parent.rb +70 -0
  201. data/lib/active_scaffold/version.rb +9 -0
  202. data/lib/active_scaffold_assets.rb +45 -0
  203. data/lib/active_scaffold_env.rb +14 -0
  204. data/lib/active_scaffold_vho.rb +2 -0
  205. data/lib/generators/active_scaffold/USAGE +29 -0
  206. data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
  207. data/lib/generators/active_scaffold_controller/USAGE +19 -0
  208. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +29 -0
  209. data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
  210. data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
  211. data/lib/generators/active_scaffold_setup/USAGE +10 -0
  212. data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +61 -0
  213. data/public/blank.html +33 -0
  214. data/shoulda_macros/macros.rb +136 -0
  215. data/test/bridges/bridge_test.rb +47 -0
  216. data/test/config/base_test.rb +15 -0
  217. data/test/config/create_test.rb +55 -0
  218. data/test/config/list_test.rb +74 -0
  219. data/test/config/show_test.rb +43 -0
  220. data/test/config/update_test.rb +17 -0
  221. data/test/const_mocker.rb +36 -0
  222. data/test/data_structures/action_columns_test.rb +113 -0
  223. data/test/data_structures/action_link_test.rb +78 -0
  224. data/test/data_structures/action_links_test.rb +78 -0
  225. data/test/data_structures/actions_test.rb +25 -0
  226. data/test/data_structures/association_column_test.rb +42 -0
  227. data/test/data_structures/column_test.rb +185 -0
  228. data/test/data_structures/columns_test.rb +69 -0
  229. data/test/data_structures/error_message_test.rb +28 -0
  230. data/test/data_structures/set_test.rb +86 -0
  231. data/test/data_structures/sorting_test.rb +126 -0
  232. data/test/data_structures/standard_column_test.rb +24 -0
  233. data/test/data_structures/virtual_column_test.rb +23 -0
  234. data/test/extensions/active_record_test.rb +45 -0
  235. data/test/extensions/array_test.rb +12 -0
  236. data/test/helpers/form_column_helpers_test.rb +31 -0
  237. data/test/helpers/list_column_helpers_test.rb +31 -0
  238. data/test/helpers/pagination_helpers_test.rb +55 -0
  239. data/test/misc/active_record_permissions_test.rb +154 -0
  240. data/test/misc/attribute_params_test.rb +110 -0
  241. data/test/misc/configurable_test.rb +96 -0
  242. data/test/misc/constraints_test.rb +193 -0
  243. data/test/misc/finder_test.rb +93 -0
  244. data/test/misc/lang_test.rb +12 -0
  245. data/test/mock_app/.gitignore +2 -0
  246. data/test/mock_app/app/controllers/application_controller.rb +10 -0
  247. data/test/mock_app/app/helpers/application_helper.rb +3 -0
  248. data/test/mock_app/config/boot.rb +110 -0
  249. data/test/mock_app/config/database.yml +16 -0
  250. data/test/mock_app/config/environment.rb +43 -0
  251. data/test/mock_app/config/environments/development.rb +17 -0
  252. data/test/mock_app/config/environments/production.rb +28 -0
  253. data/test/mock_app/config/environments/test.rb +28 -0
  254. data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
  255. data/test/mock_app/config/initializers/inflections.rb +10 -0
  256. data/test/mock_app/config/initializers/mime_types.rb +5 -0
  257. data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
  258. data/test/mock_app/config/initializers/session_store.rb +15 -0
  259. data/test/mock_app/config/locales/en.yml +5 -0
  260. data/test/mock_app/config/routes.rb +43 -0
  261. data/test/mock_app/db/test.sqlite3 +1 -0
  262. data/test/mock_app/public/blank.html +33 -0
  263. data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
  264. data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
  265. data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
  266. data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
  267. data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
  268. data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
  269. data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
  270. data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
  271. data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
  272. data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
  273. data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
  274. data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
  275. data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
  276. data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
  277. data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
  278. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
  279. data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +842 -0
  280. data/test/model_stub.rb +55 -0
  281. data/test/run_all.rb +8 -0
  282. data/test/test_helper.rb +39 -0
  283. data/uninstall.rb +13 -0
  284. metadata +497 -0
@@ -0,0 +1,1004 @@
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: jquery requires if you request for javascript that javascript
36
+ // is coming back, however rails has a different mantra
37
+ if (action_link.position) event.data_type = 'rails';
38
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible');
39
+ action_link.disable();
40
+ }
41
+ }
42
+ return true;
43
+ });
44
+ $('a.as_action').live('ajax:success', function(event, response) {
45
+ var action_link = ActiveScaffold.ActionLink.get($(this));
46
+ if (action_link) {
47
+ if (action_link.position) {
48
+ action_link.insert(response);
49
+ if (action_link.hide_target) action_link.target.hide();
50
+ } else {
51
+ action_link.enable();
52
+ }
53
+ return true;
54
+ }
55
+ return true;
56
+ });
57
+ $('a.as_action').live('ajax:complete', function(event) {
58
+ var action_link = ActiveScaffold.ActionLink.get($(this));
59
+ if (action_link) {
60
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
61
+ }
62
+ return true;
63
+ });
64
+ $('a.as_action').live('ajax:failure', function(event) {
65
+ var action_link = ActiveScaffold.ActionLink.get($(this));
66
+ if (action_link) {
67
+ ActiveScaffold.report_500_response(action_link.scaffold_id());
68
+ action_link.enable();
69
+ }
70
+ return true;
71
+ });
72
+ $('a.as_cancel').live('ajax:before', function(event) {
73
+ var as_cancel = $(this);
74
+ var action_link = ActiveScaffold.find_action_link(as_cancel);
75
+
76
+ if (action_link) {
77
+ var cancel_url = as_cancel.attr('href');
78
+ var refresh_data = as_cancel.attr('data-refresh');
79
+ if (refresh_data === 'true' && action_link.refresh_url) {
80
+ event.data_url = action_link.refresh_url;
81
+ if (action_link.position) event.data_type = 'html'
82
+ } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) {
83
+ action_link.close();
84
+ return false;
85
+ }
86
+ }
87
+ return true;
88
+ });
89
+ $('a.as_cancel').live('ajax:success', function(event, response) {
90
+ var action_link = ActiveScaffold.find_action_link($(this));
91
+
92
+ if (action_link) {
93
+ if (action_link.position) {
94
+ action_link.close(response);
95
+ } else {
96
+ response.evalResponse();
97
+ }
98
+ }
99
+ return true;
100
+ });
101
+ $('a.as_cancel').live('ajax:failure', function(event) {
102
+ var action_link = ActiveScaffold.find_action_link($(this));
103
+ if (action_link) {
104
+ ActiveScaffold.report_500_response(action_link.scaffold_id());
105
+ }
106
+ return true;
107
+ });
108
+ $('a.as_sort').live('ajax:before', function(event) {
109
+ var as_sort = $(this);
110
+ var history_controller_id = as_sort.attr('data-page-history');
111
+ if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id);
112
+ as_sort.closest('th').addClass('loading');
113
+ return true;
114
+ });
115
+ $('a.as_sort').live('ajax:failure', function(event) {
116
+ var as_scaffold = $(this).closest('.active-scaffold');
117
+ ActiveScaffold.report_500_response(as_scaffold);
118
+ return true;
119
+ });
120
+ $('span.in_place_editor_field').live('hover', function(event) {
121
+ $(this).data(); // jquery 1.4.2 workaround
122
+ if (event.type == 'mouseenter') {
123
+ if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover");
124
+ }
125
+ if (event.type == 'mouseleave') {
126
+ if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover");
127
+ }
128
+ return true;
129
+ });
130
+ $('span.in_place_editor_field').live('click', function(event) {
131
+ var span = $(this);
132
+ span.data(); // jquery 1.4.2 workaround
133
+ if (typeof(span.data('editInPlace')) === 'undefined') {
134
+ var options = {show_buttons: true,
135
+ hover_class: 'hover',
136
+ element_id: 'editor_id',
137
+ ajax_data_type: "script",
138
+ update_value: 'value'},
139
+ csrf_param = $('meta[name=csrf-param]').first(),
140
+ csrf_token = $('meta[name=csrf-token]').first(),
141
+ my_parent = span.parent(),
142
+ column_heading = null;
143
+
144
+ if(!(my_parent.is('td') || my_parent.is('th'))){
145
+ my_parent = span.parents('td').eq(0);
146
+ }
147
+
148
+ if (my_parent.is('td')) {
149
+ var column_no = my_parent.prevAll('td').length;
150
+ column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')');
151
+ } else if (my_parent.is('th')) {
152
+ column_heading = my_parent;
153
+ }
154
+
155
+ var render_url = column_heading.attr('data-ie_render_url'),
156
+ mode = column_heading.attr('data-ie_mode'),
157
+ record_id = span.attr('data-ie_id');
158
+
159
+ ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
160
+
161
+ if (span.attr('data-ie_url')) {
162
+ options.url = span.attr('data-ie_url').replace(/__id__/, record_id);
163
+ } else {
164
+ options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id);
165
+ }
166
+
167
+ if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content');
168
+
169
+ if (span.closest('div.active-scaffold').attr('data-eid')) {
170
+ if (options['params'].length > 0) {
171
+ options['params'] += "&";
172
+ }
173
+ options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid'));
174
+ }
175
+
176
+ if (mode === 'clone') {
177
+ options.clone_id_suffix = record_id;
178
+ options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern';
179
+ options.field_type = 'clone';
180
+ }
181
+
182
+ if (render_url) {
183
+ var plural = false;
184
+ if (column_heading.attr('data-ie_plural')) plural = true;
185
+ options.field_type = 'remote';
186
+ options.editor_url = render_url.replace(/__id__/, record_id)
187
+ }
188
+ if (mode === 'inline_checkbox') {
189
+ ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options);
190
+ } else {
191
+ ActiveScaffold.create_inplace_editor(span, options);
192
+ }
193
+ }
194
+ });
195
+ $('a.as_paginate').live('ajax:before',function(event) {
196
+ var as_paginate = $(this);
197
+ var history_controller_id = as_paginate.attr('data-page-history');
198
+ if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id);
199
+ as_paginate.prevAll('img.loading-indicator').css('visibility','visible');
200
+ return true;
201
+ });
202
+ $('a.as_paginate').live('ajax:failure', function(event) {
203
+ var as_scaffold = $(this).closest('.active-scaffold');
204
+ ActiveScaffold.report_500_response(as_scaffold);
205
+ return true;
206
+ });
207
+ $('a.as_paginate').live('ajax:complete', function(event) {
208
+ $(this).prevAll('img.loading-indicator').css('visibility','hidden');
209
+ return true;
210
+ });
211
+ $('input[type=button].as_add_existing').live('ajax:before', function(event) {
212
+ var url = $(this).attr('href').replace('--ID--', $(this).prev().val());
213
+ event.data_url = url;
214
+ return true;
215
+ });
216
+ $('input.update_form, select.update_form').live('change', function(event) {
217
+ var element = $(this);
218
+ var as_form = element.closest('form.as_form');
219
+ $.ajax({
220
+ url: element.attr('data-update_url'),
221
+ data: {value: element.val(),
222
+ source_id: element.attr('id')},
223
+ beforeSend: function(event) {
224
+ element.nextAll('img.loading-indicator').css('visibility','visible');
225
+ ActiveScaffold.disable_form(as_form)
226
+ },
227
+ complete: function(event) {
228
+ element.nextAll('img.loading-indicator').css('visibility','hidden');
229
+ ActiveScaffold.enable_form(as_form)
230
+ },
231
+ error: function (xhr, status, error) {
232
+ var as_div = element.closest("div.active-scaffold");
233
+ if (as_div) {
234
+ ActiveScaffold.report_500_response(as_div)
235
+ }
236
+ }
237
+ });
238
+ return true;
239
+ });
240
+
241
+ $('select.as_search_range_option').live('change', function(event) {
242
+ ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between'));
243
+ return true;
244
+ });
245
+
246
+ $('select.as_search_range_option').live('change', function(event) {
247
+ var element = $(this);
248
+ ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
249
+ ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
250
+ ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range'));
251
+ return true;
252
+ });
253
+
254
+ $('select.as_update_date_operator').live('change', function(event) {
255
+ ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next());
256
+ ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next());
257
+ return true;
258
+ });
259
+
260
+ $('a[data-popup]').live('click', function(e) {
261
+ window.open($(this).attr('href'));
262
+ e.preventDefault();
263
+ });
264
+
265
+ });
266
+
267
+ /* Simple Inheritance
268
+ http://ejohn.org/blog/simple-javascript-inheritance/
269
+ */
270
+ (function(){
271
+ var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
272
+
273
+ // The base Class implementation (does nothing)
274
+ this.Class = function(){};
275
+
276
+ // Create a new Class that inherits from this class
277
+ Class.extend = function(prop) {
278
+ var _super = this.prototype;
279
+
280
+ // Instantiate a base class (but only create the instance,
281
+ // don't run the init constructor)
282
+ initializing = true;
283
+ var prototype = new this();
284
+ initializing = false;
285
+
286
+ // Copy the properties over onto the new prototype
287
+ for (var name in prop) {
288
+ // Check if we're overwriting an existing function
289
+ prototype[name] = typeof prop[name] == "function" &&
290
+ typeof _super[name] == "function" && fnTest.test(prop[name]) ?
291
+ (function(name, fn){
292
+ return function() {
293
+ var tmp = this._super;
294
+
295
+ // Add a new ._super() method that is the same method
296
+ // but on the super-class
297
+ this._super = _super[name];
298
+
299
+ // The method only need to be bound temporarily, so we
300
+ // remove it when we're done executing
301
+ var ret = fn.apply(this, arguments);
302
+ this._super = tmp;
303
+
304
+ return ret;
305
+ };
306
+ })(name, prop[name]) :
307
+ prop[name];
308
+ }
309
+
310
+ // The dummy class constructor
311
+ function Class() {
312
+ // All construction is actually done in the init method
313
+ if ( !initializing && this.init )
314
+ this.init.apply(this, arguments);
315
+ }
316
+
317
+ // Populate our constructed prototype object
318
+ Class.prototype = prototype;
319
+
320
+ // Enforce the constructor to be what we expect
321
+ Class.constructor = Class;
322
+
323
+ // And make this class extendable
324
+ Class.extend = arguments.callee;
325
+
326
+ return Class;
327
+ };
328
+ })();
329
+
330
+ /*
331
+ jQuery delayed observer
332
+ (c) 2007 - Maxime Haineault (max@centdessin.com)
333
+
334
+ Special thanks to Stephen Goguen & Tane Piper.
335
+
336
+ Slight modifications by Elliot Winkler
337
+ */
338
+
339
+ if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
340
+ (function() {
341
+ var delayedObserverStack = [];
342
+ var observed;
343
+
344
+ function delayedObserverCallback(stackPos) {
345
+ observed = delayedObserverStack[stackPos];
346
+ if (observed.timer) return;
347
+
348
+ observed.timer = setTimeout(function(){
349
+ observed.timer = null;
350
+ observed.callback(observed.obj.val(), observed.obj);
351
+ }, observed.delay * 1000);
352
+
353
+ observed.oldVal = observed.obj.val();
354
+ }
355
+
356
+ // going by
357
+ // <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx>
358
+ // I think these codes only work when using keyup or keydown
359
+ function isNonPrintableKey(event) {
360
+ var code = event.keyCode;
361
+ return (
362
+ event.metaKey ||
363
+ (code >= 9 && code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145)
364
+ );
365
+ }
366
+
367
+ jQuery.fn.extend({
368
+ delayedObserver:function(delay, callback){
369
+ $this = $(this);
370
+
371
+ delayedObserverStack.push({
372
+ obj: $this, timer: null, delay: delay,
373
+ oldVal: $this.val(), callback: callback
374
+ });
375
+
376
+ stackPos = delayedObserverStack.length-1;
377
+
378
+ $this.keyup(function(event) {
379
+ if (isNonPrintableKey(event)) return;
380
+ observed = delayedObserverStack[stackPos];
381
+ if (observed.obj.val() == observed.obj.oldVal) return;
382
+ else delayedObserverCallback(stackPos);
383
+ });
384
+ }
385
+ });
386
+ })();
387
+ };
388
+
389
+
390
+ /*
391
+ * Simple utility methods
392
+ */
393
+
394
+ var ActiveScaffold = {
395
+ records_for: function(tbody_id) {
396
+ if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id;
397
+ return $(tbody_id).children('.record');
398
+ },
399
+ stripe: function(tbody_id) {
400
+ var even = false;
401
+ var rows = this.records_for(tbody_id);
402
+
403
+ rows.each(function (index, row_node) {
404
+ row = $(row_node);
405
+ if (row_node.tagName != 'SCRIPT'
406
+ && !row.hasClass("create")
407
+ && !row.hasClass("update")
408
+ && !row.hasClass("inline-adapter")
409
+ && !row.hasClass("active-scaffold-calculations")) {
410
+
411
+ if (even) row.addClass("even-record");
412
+ else row.removeClass("even-record");
413
+
414
+ even = !even;
415
+ }
416
+ });
417
+ },
418
+ hide_empty_message: function(tbody) {
419
+ if (this.records_for(tbody).length != 0) {
420
+ var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message')
421
+ if (empty_message_node) empty_message_node.hide();
422
+ }
423
+ },
424
+ reload_if_empty: function(tbody, url) {
425
+ if (this.records_for(tbody).length == 0) {
426
+ $.getScript(url);
427
+ }
428
+ },
429
+ removeSortClasses: function(scaffold) {
430
+ if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
431
+ scaffold = $(scaffold)
432
+ scaffold.find('td.sorted').each(function(element) {
433
+ element.removeClass("sorted");
434
+ });
435
+ scaffold.find('th.sorted').each(function(element) {
436
+ element.removeClass("sorted");
437
+ element.removeClass("asc");
438
+ element.removeClass("desc");
439
+ });
440
+ },
441
+ decrement_record_count: function(scaffold) {
442
+ // decrement the last record count, firsts record count are in nested lists
443
+ if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
444
+ scaffold = $(scaffold)
445
+ count = scaffold.find('span.active-scaffold-records').last();
446
+ if (count) count.html(parseInt(count.html(), 10) - 1);
447
+ },
448
+ increment_record_count: function(scaffold) {
449
+ // increment the last record count, firsts record count are in nested lists
450
+ if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
451
+ scaffold = $(scaffold)
452
+ count = scaffold.find('span.active-scaffold-records').last();
453
+ if (count) count.html(parseInt(count.html(), 10) + 1);
454
+ },
455
+ update_row: function(row, html) {
456
+ var even_row = false;
457
+ var replaced = null;
458
+ if (typeof(row) == 'string') row = '#' + row;
459
+ row = $(row);
460
+ if (row.hasClass('even-record')) even_row = true;
461
+
462
+ replaced = this.replace(row, html);
463
+ if (even_row === true) replaced.addClass('even-record');
464
+ ActiveScaffold.highlight(replaced);
465
+ },
466
+
467
+ replace: function(element, html) {
468
+ if (typeof(element) == 'string') element = '#' + element;
469
+ element = $(element);
470
+ element.replaceWith(html);
471
+ if (element.attr('id')) {
472
+ element = $('#' + element.attr('id'));
473
+ }
474
+ return element;
475
+ },
476
+
477
+ replace_html: function(element, html) {
478
+ if (typeof(element) == 'string') element = '#' + element;
479
+ element = $(element);
480
+ element.html(html);
481
+ return element;
482
+ },
483
+
484
+ remove: function(element) {
485
+ if (typeof(element) == 'string') element = '#' + element;
486
+ $(element).remove();
487
+ },
488
+
489
+ hide: function(element) {
490
+ if (typeof(element) == 'string') element = '#' + element;
491
+ $(element).hide();
492
+ },
493
+
494
+ show: function(element) {
495
+ if (typeof(element) == 'string') element = '#' + element;
496
+ $(element).show();
497
+ },
498
+
499
+ reset_form: function(element) {
500
+ if (typeof(element) == 'string') element = '#' + element;
501
+ $(element).get(0).reset();
502
+ },
503
+
504
+ disable_form: function(as_form) {
505
+ if (typeof(as_form) == 'string') as_form = '#' + as_form;
506
+ as_form = $(as_form)
507
+ var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
508
+ if (loading_indicator) loading_indicator.css('visibility','visible');
509
+ $('input[type=submit]', as_form).attr('disabled', 'disabled');
510
+ $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled');
511
+ },
512
+
513
+ enable_form: function(as_form) {
514
+ if (typeof(as_form) == 'string') as_form = '#' + as_form;
515
+ as_form = $(as_form)
516
+ var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator'));
517
+ if (loading_indicator) loading_indicator.css('visibility','hidden');
518
+ $('input[type=submit]', as_form).attr('disabled', '');
519
+ $("input:disabled,select:disabled,textarea:disabled", as_form).attr('disabled', '');
520
+ },
521
+
522
+ focus_first_element_of_form: function(form_element) {
523
+ if (typeof(form_element) == 'string') form_element = '#' + form_element;
524
+ $(form_element + ":first *:input[type!=hidden]:first").focus();
525
+ },
526
+
527
+ create_record_row: function(active_scaffold_id, html, options) {
528
+ if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id;
529
+ tbody = $(active_scaffold_id).find('tbody.records');
530
+
531
+ if (options.insert_at == 'top') {
532
+ tbody.prepend(html);
533
+ var new_row = tbody.children('tr.record:first-child');
534
+ } else if (options.insert_at == 'bottom') {
535
+ var rows = tbody.children('tr.record, tr.inline-adapter');
536
+ var new_row = null;
537
+ if (rows.length > 0) {
538
+ new_row = rows.last().after(html).next();
539
+ } else {
540
+ new_row = tbody.append(html).children().last();
541
+ }
542
+ }
543
+ this.stripe(tbody);
544
+ this.hide_empty_message(tbody);
545
+ this.increment_record_count(tbody.closest('div.active-scaffold'));
546
+ ActiveScaffold.highlight(new_row);
547
+ },
548
+
549
+ delete_record_row: function(row, page_reload_url) {
550
+ if (typeof(row) == 'string') row = '#' + row;
551
+ row = $(row);
552
+ var tbody = row.closest('tbody.records');
553
+
554
+ var current_action_node = row.find('td.actions a.disabled').first();
555
+ if (current_action_node) {
556
+ var action_link = ActiveScaffold.ActionLink.get(current_action_node);
557
+ if (action_link) {
558
+ action_link.close_previous_adapter();
559
+ }
560
+ }
561
+
562
+ row.remove();
563
+ this.stripe(tbody);
564
+ this.decrement_record_count(tbody.closest('div.active-scaffold'));
565
+ this.reload_if_empty(tbody, page_reload_url);
566
+ },
567
+
568
+ delete_subform_record: function(record) {
569
+ if (typeof(record) == 'string') record = '#' + record;
570
+ record = $(record);
571
+ var errors = record.prev();
572
+ if (errors.hasClass('association-record-errors')) {
573
+ this.replace_html(errors, '');
574
+ }
575
+ this.remove(record);
576
+ },
577
+
578
+ report_500_response: function(active_scaffold_id) {
579
+ server_error = $(active_scaffold_id).find('td.messages-container p.server-error');
580
+ if (!$(server_error).is(':visible')) {
581
+ server_error.show();
582
+ }
583
+ },
584
+
585
+ find_action_link: function(element) {
586
+ if (typeof(element) == 'string') element = '#' + element;
587
+ var as_adapter = $(element).closest('.as_adapter');
588
+ return ActiveScaffold.ActionLink.get(as_adapter);
589
+ },
590
+
591
+ scroll_to: function(element) {
592
+ if (typeof(element) == 'string') element = '#' + element;
593
+ var form_offset = $(element).offset(),
594
+ destination = form_offset.top;
595
+ $(document).scrollTop(destination);
596
+ },
597
+
598
+ process_checkbox_inplace_edit: function(checkbox, options) {
599
+ var checked = checkbox.is(':checked');
600
+ if (checked === true) options['params'] += '&value=1';
601
+ $.ajax({
602
+ url: options.url,
603
+ type: "POST",
604
+ data: options['params'],
605
+ dataType: options.ajax_data_type,
606
+ after: function(request){
607
+ checkbox.attr('disabled', 'disabled');
608
+ },
609
+ complete: function(request){
610
+ checkbox.attr('disabled', '');
611
+ }
612
+ });
613
+ },
614
+
615
+ read_inplace_edit_heading_attributes: function(column_heading, options) {
616
+ if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>";
617
+ if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text');
618
+ if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text');
619
+ if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>";
620
+ if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows');
621
+ if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols');
622
+ if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size');
623
+ },
624
+
625
+ create_inplace_editor: function(span, options) {
626
+ span.removeClass('hover');
627
+ span.editInPlace(options);
628
+ span.trigger('click.editInPlace');
629
+ },
630
+
631
+ highlight: function(element) {
632
+ if (typeof(element) == 'string') element = '#' + element;
633
+ if (typeof(element.effect) == 'function') {
634
+ element.effect("highlight", {}, 3000);
635
+ }
636
+ },
637
+
638
+ create_visibility_toggle: function(element, options) {
639
+ if (typeof(element) == 'string') element = '#' + element;
640
+ var toggable = $(element);
641
+ var toggler = toggable.prev();
642
+ var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label;
643
+
644
+ toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)');
645
+ toggler.children('a').click(function() {
646
+ toggable.toggle();
647
+ $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label);
648
+ return false;
649
+ });
650
+ },
651
+
652
+ create_associated_record_form: function(element, content, options) {
653
+ if (typeof(element) == 'string') element = '#' + element;
654
+ var element = $(element);
655
+ if (options.singular == false) {
656
+ if (!(options.id && $('#' + options.id).size() > 0)) {
657
+ element.append(content);
658
+ }
659
+ } else {
660
+ var current = $('#' + element.attr('id') + ' tr.association-record')
661
+ if (current[0]) {
662
+ this.replace(current[0], content);
663
+ } else {
664
+ element.prepend(content);
665
+ }
666
+ }
667
+ },
668
+
669
+ render_form_field: function(source, content, options) {
670
+ if (typeof(source) == 'string') source = '#' + source;
671
+ var source = $(source);
672
+ var element = source.closest('.association-record');
673
+ if (element.length == 0) {
674
+ element = source.closest('ol.form');
675
+ }
676
+ element = element.find('.' + options.field_class);
677
+
678
+ if (element) {
679
+ if (options.is_subform == false) {
680
+ this.replace(element.closest('dl'), content);
681
+ } else {
682
+ this.replace_html(element, content);
683
+ }
684
+ }
685
+ },
686
+
687
+ sortable: function(element, controller, options, url_params) {
688
+ if (typeof(element) == 'string') element = '#' + element;
689
+ var element = $(element);
690
+ var sortable_options = {};
691
+ if (options.update === true) {
692
+ url_params.authenticity_token = $('meta[name=csrf-param]').attr('content');
693
+ sortable_options.update = function(event, ui) {
694
+ var url = controller + '/' + options.action + '?'
695
+ url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/});
696
+ $.post(url.append_params(url_params));
697
+ }
698
+ }
699
+ element.sortable(sortable_options);
700
+ },
701
+
702
+ record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
703
+ $.ajax({
704
+ url: edit_associated_url.split('--ID--').join(id),
705
+ error: function(xhr, textStatus, errorThrown){
706
+ ActiveScaffold.report_500_response(active_scaffold_id)
707
+ }
708
+ });
709
+ },
710
+
711
+ // element is tbody id
712
+ mark_records: function(element, options) {
713
+ if (typeof(element) == 'string') element = '#' + element;
714
+ var element = $(element);
715
+ var mark_checkboxes = $('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]');
716
+ mark_checkboxes.each(function (index) {
717
+ var item = $(this);
718
+ if(options.checked === true) {
719
+ item.attr('checked', 'checked');
720
+ } else {
721
+ item.removeAttr('checked');
722
+ }
723
+ item.attr('value', ('' + !options.checked));
724
+ });
725
+ if(options.include_mark_all === true) {
726
+ var mark_all_checkbox = element.prev('thead').find('th.marked-column_heading span input[type="checkbox"]');
727
+ if(options.checked === true) {
728
+ mark_all_checkbox.attr('checked', 'checked');
729
+ } else {
730
+ mark_all_checkbox.removeAttr('checked');
731
+ }
732
+ mark_all_checkbox.attr('value', ('' + !options.checked));
733
+ }
734
+ }
735
+ }
736
+
737
+ /*
738
+ * DHTML history tie-in
739
+ */
740
+ function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
741
+ if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
742
+
743
+ var array = url.split('?');
744
+ var qs = new Querystring(array[1]);
745
+ var sort = qs.get('sort')
746
+ var dir = qs.get('sort_direction')
747
+ var page = qs.get('page')
748
+ if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
749
+ }
750
+
751
+ /*
752
+ * URL modification support. Incomplete functionality.
753
+ */
754
+ String.prototype.append_params = function(params) {
755
+ var url = this;
756
+ if (url.indexOf('?') == -1) url += '?';
757
+ else if (url.lastIndexOf('&') != url.length) url += '&';
758
+
759
+ for(var key in params) {
760
+ if (key) url += (key + '=' + params[key] + '&');
761
+ }
762
+
763
+ // the loop leaves a comma dangling at the end of string, chop it off
764
+ url = url.substring(0, url.length-1);
765
+ return url;
766
+ };
767
+
768
+
769
+ /**
770
+ * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
771
+ */
772
+ ActiveScaffold.Actions = new Object();
773
+ ActiveScaffold.Actions.Abstract = Class.extend({
774
+ init: function(links, target, loading_indicator, options) {
775
+ this.target = $(target);
776
+ this.loading_indicator = $(loading_indicator);
777
+ this.options = options;
778
+ var _this = this;
779
+ this.links = $.map(links, function(link) {
780
+ var my_link = _this.instantiate_link(link);
781
+ return my_link;
782
+ });
783
+ },
784
+
785
+ instantiate_link: function(link) {
786
+ throw 'unimplemented'
787
+ }
788
+ });
789
+
790
+ /**
791
+ * A DataStructures::ActionLink, represented in JavaScript.
792
+ * Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
793
+ */
794
+ ActiveScaffold.ActionLink = {
795
+ get: function(element) {
796
+ if (typeof(element) == 'string') element = '#' + element;
797
+ var element = $(element);
798
+ if (element.length > 0) {
799
+ element.data(); // jquery 1.4.2 workaround
800
+ if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) {
801
+ var parent = element.closest('.actions');
802
+ if (parent.length === 0) {
803
+ // maybe an column action_link
804
+ parent = element.parent();
805
+ }
806
+ if (parent && parent.is('td')) {
807
+ // record action
808
+ parent = parent.closest('tr.record');
809
+ var target = parent.find('a.as_action');
810
+ var loading_indicator = parent.find('td.actions .loading-indicator');
811
+ new ActiveScaffold.Actions.Record(target, parent, loading_indicator);
812
+ } else if (parent && parent.is('div')) {
813
+ //table action
814
+ new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator'));
815
+ }
816
+ element = $(element);
817
+ }
818
+ return element.data('action_link');
819
+ } else {
820
+ return null;
821
+ }
822
+ }
823
+ };
824
+ ActiveScaffold.ActionLink.Abstract = Class.extend({
825
+ init: function(a, target, loading_indicator) {
826
+ this.tag = $(a);
827
+ this.url = this.tag.attr('href');
828
+ this.method = this.tag.attr('data-method') || 'get';
829
+ this.target = target;
830
+ this.loading_indicator = loading_indicator;
831
+ this.hide_target = false;
832
+ this.position = this.tag.attr('data-position');
833
+
834
+ this.tag.data('action_link', this);
835
+ return this;
836
+ },
837
+
838
+ open: function(event) {
839
+ },
840
+
841
+ insert: function(content) {
842
+ throw 'unimplemented'
843
+ },
844
+
845
+ close: function() {
846
+ this.enable();
847
+ this.adapter.remove();
848
+ if (this.hide_target) this.target.show();
849
+ },
850
+
851
+ reload: function() {
852
+ this.close();
853
+ this.open();
854
+ },
855
+
856
+ get_new_adapter_id: function() {
857
+ var id = 'adapter_';
858
+ var i = 0;
859
+ while ($(id + i)) i++;
860
+ return id + i;
861
+ },
862
+
863
+ enable: function() {
864
+ return this.tag.removeClass('disabled');
865
+ },
866
+
867
+ disable: function() {
868
+ return this.tag.addClass('disabled');
869
+ },
870
+
871
+ is_disabled: function() {
872
+ return this.tag.hasClass('disabled');
873
+ },
874
+
875
+ scaffold_id: function() {
876
+ return '#' + this.tag.closest('div.active-scaffold').attr('id');
877
+ },
878
+
879
+ scaffold: function() {
880
+ return this.tag.closest('div.active-scaffold');
881
+ },
882
+
883
+ update_flash_messages: function(messages) {
884
+ message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages'));
885
+ if (message_node) message_node.html(messages);
886
+ },
887
+ set_adapter: function(element) {
888
+ this.adapter = element;
889
+ this.adapter.addClass('as_adapter');
890
+ this.adapter.data('action_link', this);
891
+ }
892
+ });
893
+
894
+ /**
895
+ * Concrete classes for record actions
896
+ */
897
+ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
898
+ instantiate_link: function(link) {
899
+ var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
900
+ var refresh = this.target.attr('data-refresh');
901
+ if (refresh) l.refresh_url = refresh;
902
+
903
+ if (l.position) {
904
+ l.url = l.url.append_params({adapter: '_list_inline_adapter'});
905
+ l.tag.attr('href', l.url);
906
+ }
907
+ l.set = this;
908
+ return l;
909
+ }
910
+ });
911
+
912
+ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
913
+ close_previous_adapter: function() {
914
+ var _this = this;
915
+ $.each(this.set.links, function(index, item) {
916
+ if (item.url != _this.url && item.is_disabled() && item.adapter) {
917
+ item.enable();
918
+ item.adapter.remove();
919
+ }
920
+ });
921
+ },
922
+
923
+ insert: function(content) {
924
+ this.close_previous_adapter();
925
+
926
+ if (this.position == 'replace') {
927
+ this.position = 'after';
928
+ this.hide_target = true;
929
+ }
930
+
931
+ if (this.position == 'after') {
932
+ this.target.after(content);
933
+ this.set_adapter(this.target.next());
934
+ }
935
+ else if (this.position == 'before') {
936
+ this.target.before(content);
937
+ this.set_adapter(this.target.prev());
938
+ }
939
+ else {
940
+ return false;
941
+ }
942
+ ActiveScaffold.highlight(this.adapter.find('td'));
943
+ },
944
+
945
+ close: function(refreshed_content) {
946
+ if (refreshed_content) {
947
+ ActiveScaffold.update_row(this.target, refreshed_content);
948
+ }
949
+ this._super();
950
+ },
951
+
952
+ enable: function() {
953
+ var _this = this;
954
+ $.each(this.set.links, function(index, item) {
955
+ if (item.url != _this.url) return;
956
+ item.tag.removeClass('disabled');
957
+ });
958
+ },
959
+
960
+ disable: function() {
961
+ var _this = this;
962
+ $.each(this.set.links, function(index, item) {
963
+ if (item.url != _this.url) return;
964
+ item.tag.addClass('disabled');
965
+ });
966
+ },
967
+
968
+ set_opened: function() {
969
+ if (this.position == 'after') {
970
+ this.set_adapter(this.target.next());
971
+ }
972
+ else if (this.position == 'before') {
973
+ this.set_adapter(this.target.prev());
974
+ }
975
+ this.disable();
976
+ }
977
+ });
978
+
979
+ /**
980
+ * Concrete classes for table actions
981
+ */
982
+ ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({
983
+ instantiate_link: function(link) {
984
+ var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
985
+ if (l.position) {
986
+ l.url = l.url.append_params({adapter: '_list_inline_adapter'});
987
+ l.tag.attr('href', l.url);
988
+ }
989
+ return l;
990
+ }
991
+ });
992
+
993
+ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
994
+ insert: function(content) {
995
+ if (this.position == 'top') {
996
+ this.target.prepend(content);
997
+ this.set_adapter(this.target.children().first());
998
+ }
999
+ else {
1000
+ throw 'Unknown position "' + this.position + '"'
1001
+ }
1002
+ ActiveScaffold.highlight(this.adapter.find('td').first().children());
1003
+ }
1004
+ });