active_scaffold_vho 3.0.6

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