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
+ if (typeof Prototype == 'undefined')
2
+ {
3
+ warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>).";
4
+ alert(warning);
5
+ }
6
+ if (Prototype.Version.substring(0, 3) < '1.6')
7
+ {
8
+ warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts).";
9
+ alert(warning);
10
+ }
11
+ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction});
12
+
13
+
14
+ document.observe("dom:loaded", function() {
15
+ document.on('ajax:create', 'form.as_form', function(event) {
16
+ var source = event.findElement();
17
+ var as_form = event.findElement('form');
18
+ if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') {
19
+ // Hack: Prototype or rails.js somehow screw up event handling if someone clicks
20
+ // a button of type button such as Create Another <Association>
21
+ // as a result form is disabled but never reenabled..
22
+ } else {
23
+ if (as_form && as_form.readAttribute('data-loading') == 'true') {
24
+ ActiveScaffold.disable_form(as_form);
25
+ }
26
+ }
27
+ return true;
28
+ });
29
+ document.on('ajax:complete', 'form.as_form', function(event) {
30
+ var as_form = event.findElement('form');
31
+ if (as_form && as_form.readAttribute('data-loading') == 'true') {
32
+ ActiveScaffold.enable_form(as_form);
33
+ event.stop();
34
+ return false;
35
+ }
36
+ });
37
+ document.on('ajax:failure', 'form.as_form', function(event) {
38
+ var as_div = event.findElement('div.active-scaffold');
39
+ if (as_div) {
40
+ ActiveScaffold.report_500_response(as_div)
41
+ event.stop();
42
+ return false;
43
+ }
44
+ });
45
+ document.on('submit', 'form.as_form.as_remote_upload', function(event) {
46
+ var as_form = event.findElement('form');
47
+ if (as_form && as_form.readAttribute('data-loading') == 'true') {
48
+ setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10);
49
+ }
50
+ return true;
51
+ });
52
+ document.on('ajax:before', 'a.as_action', function(event) {
53
+ var action_link = ActiveScaffold.ActionLink.get(event.findElement());
54
+ if (action_link) {
55
+ if (action_link.is_disabled()) {
56
+ event.stop();
57
+ } else {
58
+ if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible';
59
+ action_link.disable();
60
+ }
61
+ }
62
+ return true;
63
+ });
64
+ document.on('ajax:success', 'a.as_action', function(event) {
65
+ var action_link = ActiveScaffold.ActionLink.get(event.findElement());
66
+ if (action_link && event.memo && event.memo.request) {
67
+ if (action_link.position) {
68
+ action_link.insert(event.memo.request.transport.responseText);
69
+ if (action_link.hide_target) action_link.target.hide();
70
+ } else {
71
+ //event.memo.request.evalResponse(); // (clyfe) prototype evals the response by itself checking headers, this would eval twice
72
+ action_link.enable();
73
+ }
74
+ event.stop();
75
+ }
76
+ return true;
77
+ });
78
+ document.on('ajax:complete', 'a.as_action', function(event) {
79
+ var action_link = ActiveScaffold.ActionLink.get(event.findElement());
80
+ if (action_link && action_link.loading_indicator) {
81
+ action_link.loading_indicator.style.visibility = 'hidden';
82
+ }
83
+ return true;
84
+ });
85
+ document.on('ajax:failure', 'a.as_action', function(event) {
86
+ var action_link = ActiveScaffold.ActionLink.get(event.findElement());
87
+ if (action_link) {
88
+ ActiveScaffold.report_500_response(action_link.scaffold_id());
89
+ action_link.enable();
90
+ }
91
+ return true;
92
+ });
93
+ document.on('ajax:before', 'a.as_cancel', function(event) {
94
+ var as_cancel = event.findElement();
95
+ var action_link = ActiveScaffold.find_action_link(as_cancel);
96
+
97
+ if (action_link) {
98
+ var refresh_data = as_cancel.readAttribute('data-refresh');
99
+ if (refresh_data === 'true' && action_link.refresh_url) {
100
+ event.memo.url = action_link.refresh_url;
101
+ } else if (refresh_data === 'false' || as_cancel.readAttribute('href').blank()) {
102
+ action_link.close();
103
+ event.stop();
104
+ }
105
+ }
106
+ return true;
107
+ });
108
+ document.on('ajax:success', 'a.as_cancel', function(event) {
109
+ var action_link = ActiveScaffold.find_action_link(event.findElement());
110
+ if (action_link) {
111
+ if (action_link.position) {
112
+ action_link.close(event.memo.request.responseText);
113
+ } else {
114
+ event.memo.request.evalResponse();
115
+ }
116
+ }
117
+ return true;
118
+ });
119
+ document.on('ajax:failure', 'a.as_cancel', function(event) {
120
+ var action_link = ActiveScaffold.find_action_link(event.findElement());
121
+ if (action_link) {
122
+ ActiveScaffold.report_500_response(action_link.scaffold_id());
123
+ }
124
+ return true;
125
+ });
126
+ document.on('ajax:before', 'a.as_sort', function(event) {
127
+ var as_sort = event.findElement();
128
+ var history_controller_id = as_sort.readAttribute('data-page-history');
129
+ if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.readAttribute('href'), history_controller_id);
130
+ as_sort.up('th').addClassName('loading');
131
+ return true;
132
+ });
133
+ document.on('ajax:failure', 'a.as_sort', function(event) {
134
+ var as_scaffold = event.findElement('.active-scaffold');
135
+ ActiveScaffold.report_500_response(as_scaffold);
136
+ return true;
137
+ });
138
+ document.on('mouseover', 'span.in_place_editor_field', function(event) {
139
+ event.findElement().addClassName('hover');
140
+ });
141
+ document.on('mouseout', 'span.in_place_editor_field', function(event) {
142
+ event.findElement().removeClassName('hover');
143
+ });
144
+ document.on('click', 'span.in_place_editor_field', function(event) {
145
+ var span = event.findElement('span.in_place_editor_field');
146
+
147
+ if (typeof(span.inplace_edit) === 'undefined') {
148
+ var options = {htmlResponse: false,
149
+ onEnterHover: null,
150
+ onLeaveHover: null,
151
+ onComplete: null,
152
+ params: '',
153
+ ajaxOptions: {method: 'post'}},
154
+ csrf_param = $$('meta[name=csrf-param]')[0],
155
+ csrf_token = $$('meta[name=csrf-token]')[0],
156
+ my_parent = span.up(),
157
+ column_heading = null;
158
+
159
+ if (my_parent.nodeName.toLowerCase() === 'td') {
160
+ var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading';
161
+ column_heading = span.up('.active-scaffold').down(heading_selector);
162
+ } else if (my_parent.nodeName.toLowerCase() === 'th') {
163
+ column_heading = my_parent;
164
+ }
165
+
166
+ var render_url = column_heading.readAttribute('data-ie_render_url'),
167
+ mode = column_heading.readAttribute('data-ie_mode'),
168
+ record_id = span.readAttribute('data-ie_id');
169
+
170
+ ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options);
171
+
172
+ if (span.readAttribute('data-ie_url')) {
173
+ options.url = span.readAttribute('data-ie_url');
174
+ } else {
175
+ options.url = column_heading.readAttribute('data-ie_url');
176
+ }
177
+ if (record_id) options.url = options.url.sub('__id__', record_id);
178
+
179
+ if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content');
180
+
181
+ if (span.up('div.active-scaffold').readAttribute('data-eid')) {
182
+ if (options['params'].length > 0) {
183
+ options['params'] += ";";
184
+ }
185
+ options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid'));
186
+ }
187
+
188
+ if (mode === 'clone') {
189
+ options.nodeIdSuffix = record_id;
190
+ options.inplacePatternSelector = '#' + column_heading.readAttribute('id') + ' .as_inplace_pattern';
191
+ options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();');
192
+ }
193
+
194
+ if (render_url) {
195
+ var plural = false;
196
+ if (column_heading.readAttribute('data-ie_plural')) plural = true;
197
+ options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});');
198
+ }
199
+
200
+ if (mode === 'inline_checkbox') {
201
+ ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options);
202
+ } else {
203
+ ActiveScaffold.create_inplace_editor(span, options);
204
+ }
205
+ }
206
+ return true;
207
+ });
208
+ document.on('ajax:before', 'a.as_paginate', function(event) {
209
+ var as_paginate = event.findElement();
210
+ var loading_indicator = as_paginate.up().down('img.loading-indicator');
211
+ var history_controller_id = as_paginate.readAttribute('data-page-history');
212
+
213
+ if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.readAttribute('href'), history_controller_id);
214
+ if (loading_indicator) loading_indicator.style.visibility = 'visible';
215
+ return true;
216
+ });
217
+ document.on('ajax:failure', 'a.as_paginate', function(event) {
218
+ var as_scaffold = event.findElement('.active-scaffold');
219
+ ActiveScaffold.report_500_response(as_scaffold);
220
+ return true;
221
+ });
222
+ document.on('ajax:complete', 'a.as_paginate', function(event) {
223
+ var as_paginate = event.findElement();
224
+ var loading_indicator = as_paginate.up().down('img.loading-indicator');
225
+
226
+ if(loading_indicator) loading_indicator.style.visibility = 'hidden';
227
+ return true;
228
+ });
229
+ document.on('ajax:before', 'input[type=button].as_add_existing', function(event) {
230
+ var button = event.findElement();
231
+ var url = button.readAttribute('href').sub('--ID--', button.previous().getValue());
232
+ event.memo.url = url;
233
+ return true;
234
+ });
235
+ document.on('change', 'input.update_form, select.update_form', function(event) {
236
+ var element = event.findElement();
237
+ var as_form = element.up('form.as_form');
238
+
239
+ new Ajax.Request(element.readAttribute('data-update_url'), {
240
+ method: 'get',
241
+ parameters: {value: element.getValue()},
242
+ onLoading: function(response) {
243
+ element.next('img.loading-indicator').style.visibility = 'visible';
244
+ as_form.disable();
245
+ },
246
+ onComplete: function(response) {
247
+ element.next('img.loading-indicator').style.visibility = 'hidden';
248
+ as_form.enable();
249
+ },
250
+ onFailure: function(request) {
251
+ var as_div = event.findElement('div.active-scaffold');
252
+ if (as_div) {
253
+ ActiveScaffold.report_500_response(as_div)
254
+ }
255
+ }
256
+ });
257
+ return true;
258
+ });
259
+ document.on('change', 'select.as_search_range_option', function(event) {
260
+ var element = event.findElement();
261
+ Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between'));
262
+ return true;
263
+ });
264
+ document.on('change', 'select.as_search_date_time_option', function(event) {
265
+ var element = event.findElement();
266
+ Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric'));
267
+ Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend'));
268
+ Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range'));
269
+ return true;
270
+ });
271
+ document.on('change', 'select.as_update_date_operator', function(event) {
272
+ var element = event.findElement();
273
+ Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next());
274
+ Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next());
275
+ Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span'));
276
+ return true;
277
+ });
278
+ document.on("click", "a[data-popup]", function(event, element) {
279
+ if (event.stopped) return;
280
+ window.open($(element).href);
281
+ event.stop();
282
+ });
283
+ });
284
+
285
+
286
+ /*
287
+ * Simple utility methods
288
+ */
289
+
290
+ var ActiveScaffold = {
291
+ records_for: function(tbody_id) {
292
+ var rows = [];
293
+ var child = $(tbody_id).down('.record');
294
+ while (child) {
295
+ rows.push(child);
296
+ child = child.next('.record');
297
+ }
298
+ return rows;
299
+ },
300
+ stripe: function(tbody_id) {
301
+ var even = false;
302
+ var rows = this.records_for(tbody_id);
303
+ for (var i = 0; i < rows.length; i++) {
304
+ var child = rows[i];
305
+ //Make sure to skip rows that are create or edit rows or messages
306
+ if (child.tagName != 'SCRIPT'
307
+ && !child.hasClassName("create")
308
+ && !child.hasClassName("update")
309
+ && !child.hasClassName("inline-adapter")
310
+ && !child.hasClassName("active-scaffold-calculations")) {
311
+
312
+ if (even) child.addClassName("even-record");
313
+ else child.removeClassName("even-record");
314
+
315
+ even = !even;
316
+ }
317
+ }
318
+ },
319
+ hide_empty_message: function(tbody) {
320
+ if (this.records_for(tbody).length != 0) {
321
+ var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message')
322
+ empty_message_nodes.invoke('hide');
323
+ }
324
+ },
325
+ reload_if_empty: function(tbody, url) {
326
+ if (this.records_for(tbody).length == 0) {
327
+ new Ajax.Request(url, {
328
+ method: 'get',
329
+ asynchronous: true,
330
+ evalScripts: true
331
+ });
332
+ }
333
+ },
334
+ removeSortClasses: function(scaffold) {
335
+ scaffold = $(scaffold)
336
+ scaffold.select('td.sorted').each(function(element) {
337
+ element.removeClassName("sorted");
338
+ });
339
+ scaffold.select('th.sorted').each(function(element) {
340
+ element.removeClassName("sorted");
341
+ element.removeClassName("asc");
342
+ element.removeClassName("desc");
343
+ });
344
+ },
345
+ decrement_record_count: function(scaffold) {
346
+ // decrement the last record count, firsts record count are in nested lists
347
+ scaffold = $(scaffold)
348
+ count = scaffold.select('span.active-scaffold-records').last();
349
+ if (count) count.update(parseInt(count.innerHTML, 10) - 1);
350
+ },
351
+ increment_record_count: function(scaffold) {
352
+ // increment the last record count, firsts record count are in nested lists
353
+ scaffold = $(scaffold)
354
+ count = scaffold.select('span.active-scaffold-records').last();
355
+ if (count) count.update(parseInt(count.innerHTML, 10) + 1);
356
+ },
357
+ update_row: function(row, html) {
358
+ row = $(row);
359
+ var new_row = this.replace(row, html)
360
+ if (row.hasClassName('even-record')) new_row.addClassName('even-record');
361
+ new_row.highlight();
362
+ },
363
+
364
+ replace: function(element, html) {
365
+ element = $(element)
366
+ Element.replace(element, html);
367
+ element = $(element.readAttribute('id'));
368
+ return element;
369
+ },
370
+
371
+ replace_html: function(element, html) {
372
+ element = $(element);
373
+ element.update(html);
374
+ return element;
375
+ },
376
+
377
+ remove: function(element) {
378
+ $(element).remove();
379
+ },
380
+
381
+ hide: function(element) {
382
+ $(element).hide();
383
+ },
384
+
385
+ show: function(element) {
386
+ $(element).show();
387
+ },
388
+
389
+ reset_form: function(element) {
390
+ $(element).reset();
391
+ },
392
+
393
+ disable_form: function(as_form) {
394
+ as_form = $(as_form)
395
+ var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
396
+ if (loading_indicator) loading_indicator.style.visibility = 'visible';
397
+ as_form.disable();
398
+ },
399
+
400
+ enable_form: function(as_form) {
401
+ as_form = $(as_form)
402
+ var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator'));
403
+ if (loading_indicator) loading_indicator.style.visibility = 'hidden';
404
+ as_form.enable();
405
+ },
406
+
407
+ focus_first_element_of_form: function(form_element) {
408
+ Form.focusFirstElement(form_element);
409
+ },
410
+
411
+ create_record_row: function(active_scaffold_id, html, options) {
412
+ tbody = $(active_scaffold_id).down('tbody.records');
413
+
414
+ var new_row = null;
415
+
416
+ if (options.insert_at == 'top') {
417
+ tbody.insert({top: html});
418
+ new_row = tbody.firstDescendant();
419
+ } else if (options.insert_at == 'bottom') {
420
+ var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')});
421
+ if (last_row) {
422
+ last_row.insert({after: html});
423
+ } else {
424
+ tbody.insert({bottom: html});
425
+ }
426
+ new_row = Selector.findChildElements(tbody, ['tr.record']).last();
427
+ }
428
+
429
+ this.stripe(tbody);
430
+ this.hide_empty_message(tbody);
431
+ this.increment_record_count(tbody.up('div.active-scaffold'));
432
+ new_row.highlight();
433
+ },
434
+
435
+ delete_record_row: function(row, page_reload_url) {
436
+ row = $(row);
437
+ var tbody = row.up('tbody.records');
438
+
439
+ var current_action_node = row.down('td.actions a.disabled');
440
+
441
+ if (current_action_node) {
442
+ var action_link = ActiveScaffold.ActionLink.get(current_action_node);
443
+ if (action_link) {
444
+ action_link.close_previous_adapter();
445
+ }
446
+ }
447
+ row.remove();
448
+ this.stripe(tbody);
449
+ this.decrement_record_count(tbody.up('div.active-scaffold'));
450
+ this.reload_if_empty(tbody, page_reload_url);
451
+ },
452
+
453
+ report_500_response: function(active_scaffold_id) {
454
+ server_error = $(active_scaffold_id).down('td.messages-container p.server-error');
455
+ if (server_error.visible()) {
456
+ server_error.highlight();
457
+ } else {
458
+ server_error.show();
459
+ }
460
+ },
461
+
462
+ find_action_link: function(element) {
463
+ return ActiveScaffold.ActionLink.get($(element).up('.as_adapter'));
464
+ },
465
+
466
+ scroll_to: function(element) {
467
+ $(element).scrollTo();
468
+ },
469
+
470
+ process_checkbox_inplace_edit: function(checkbox, options) {
471
+ var checked = checkbox.readAttribute('checked');
472
+ // checked attribute is nt updated
473
+ if (checked !== 'checked') options['params'] += '&value=1';
474
+ new Ajax.Request(options.url, {
475
+ method: 'post',
476
+ parameters: options['params'],
477
+ onCreate: function(response) {
478
+ checkbox.disable();
479
+ },
480
+ onComplete: function(response) {
481
+ checkbox.enable();
482
+ }
483
+ });
484
+ },
485
+
486
+ read_inplace_edit_heading_attributes: function(column_heading, options) {
487
+ if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text');
488
+ if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text');
489
+ if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text');
490
+ if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text');
491
+ if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows');
492
+ if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols');
493
+ if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size');
494
+ },
495
+
496
+ create_inplace_editor: function(span, options) {
497
+ if (options['params'].length > 0) {
498
+ options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';");
499
+ }
500
+ span.removeClassName('hover');
501
+ span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options)
502
+ span.inplace_edit.enterEditMode();
503
+ },
504
+
505
+ create_visibility_toggle: function(element, options) {
506
+ var toggable = $(element);
507
+ var toggler = toggable.previous();
508
+ var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label;
509
+
510
+ toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)');
511
+ toggler.firstDescendant().observe('click', function(event) {
512
+ var element = event.element();
513
+ toggable.toggle();
514
+ element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label;
515
+ });
516
+ },
517
+
518
+ create_associated_record_form: function(element, content, options) {
519
+ var element = $(element);
520
+ if (options.singular == false) {
521
+ if (!(options.id && $(options.id))) {
522
+ element.insert(content);
523
+ }
524
+ } else {
525
+ var current = $$('#' + element.readAttribute('id') + ' tr.association-record');
526
+ if (current[0]) {
527
+ this.replace(current[0], content);
528
+ } else {
529
+ element.insert({top: content});
530
+ }
531
+ }
532
+ },
533
+
534
+ render_form_field: function(element, content, options) {
535
+ var element = $(element);
536
+ if (options.is_subform == false) {
537
+ this.replace(element.up('dl'), content);
538
+ } else {
539
+ this.replace_html(element, content);
540
+ }
541
+ },
542
+
543
+ record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
544
+ new Ajax.Request(
545
+ edit_associated_url.sub('--ID--', id), {
546
+ asynchronous: true,
547
+ evalScripts: true,
548
+ onFailure: function(){
549
+ ActiveScaffold.report_500_response(active_scaffold_id.to_json)
550
+ }
551
+ }
552
+ );
553
+ }
554
+ }
555
+
556
+ /*
557
+ * DHTML history tie-in
558
+ */
559
+ function addActiveScaffoldPageToHistory(url, active_scaffold_id) {
560
+ if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded
561
+
562
+ var array = url.split('?');
563
+ var qs = new Querystring(array[1]);
564
+ var sort = qs.get('sort')
565
+ var dir = qs.get('sort_direction')
566
+ var page = qs.get('page')
567
+ if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url);
568
+ }
569
+
570
+ /*
571
+ * Add-ons/Patches to Prototype
572
+ */
573
+
574
+ /* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */
575
+ Element.replace = function(element, html) {
576
+ element = $(element);
577
+ if (element.outerHTML) {
578
+ try {
579
+ element.outerHTML = html.stripScripts();
580
+ } catch (e) {
581
+ var tn = element.tagName;
582
+ if(tn=='TBODY' || tn=='TR' || tn=='TD')
583
+ {
584
+ var tempDiv = document.createElement("div");
585
+ tempDiv.innerHTML = '<table id="tempTable" style="display: none">' + html.stripScripts() + '</table>';
586
+ element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element);
587
+ }
588
+ else throw e;
589
+ }
590
+ } else {
591
+ var range = element.ownerDocument.createRange();
592
+ /* patch to fix <form> replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */
593
+ range.selectNodeContents(element.parentNode);
594
+ element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element);
595
+ }
596
+ setTimeout(function() {html.evalScripts()}, 10);
597
+ return element;
598
+ };
599
+
600
+ /*
601
+ * URL modification support. Incomplete functionality.
602
+ */
603
+ Object.extend(String.prototype, {
604
+ append_params: function(params) {
605
+ url = this;
606
+ if (url.indexOf('?') == -1) url += '?';
607
+ else if (url.lastIndexOf('&') != url.length) url += '&';
608
+
609
+ url += $H(params).collect(function(item) {
610
+ return item.key + '=' + item.value;
611
+ }).join('&');
612
+
613
+ return url;
614
+ }
615
+ });
616
+
617
+ /*
618
+ * Prototype's implementation was throwing an error instead of false
619
+ */
620
+ Element.Methods.Simulated = {
621
+ hasAttribute: function(element, attribute) {
622
+ var t = Element._attributeTranslations;
623
+ attribute = (t.names && t.names[attribute]) || attribute;
624
+ // Return false if we get an error here
625
+ try {
626
+ return $(element).getAttributeNode(attribute).specified;
627
+ } catch (e) {
628
+ return false;
629
+ }
630
+ }
631
+ };
632
+
633
+ /**
634
+ * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc.
635
+ */
636
+ ActiveScaffold.Actions = new Object();
637
+ ActiveScaffold.Actions.Abstract = Class.create({
638
+ initialize: function(links, target, loading_indicator, options) {
639
+ this.target = $(target);
640
+ this.loading_indicator = $(loading_indicator);
641
+ this.options = options;
642
+ this.links = links.collect(function(link) {
643
+ return this.instantiate_link(link);
644
+ }.bind(this));
645
+ },
646
+
647
+ instantiate_link: function(link) {
648
+ throw 'unimplemented'
649
+ }
650
+ });
651
+
652
+ /**
653
+ * A DataStructures::ActionLink, represented in JavaScript.
654
+ * Concerned with AJAX-enabling a link and adapting the result for insertion into the table.
655
+ */
656
+ ActiveScaffold.ActionLink = {
657
+ get: function(element) {
658
+ var element = $(element);
659
+ if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) {
660
+ var parent = element.up('.actions');
661
+ if (typeof(parent) === 'undefined') {
662
+ // maybe an column action_link
663
+ parent = element.up();
664
+ }
665
+ if (parent && parent.nodeName.toUpperCase() == 'TD') {
666
+ // record action
667
+ parent = parent.up('tr.record')
668
+ new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator'));
669
+ } else if (parent && parent.nodeName.toUpperCase() == 'DIV') {
670
+ //table action
671
+ new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator'));
672
+ }
673
+ element = $(element);
674
+ }
675
+ return element.retrieve('action_link');
676
+ }
677
+ };
678
+
679
+ ActiveScaffold.ActionLink.Abstract = Class.create({
680
+ initialize: function(a, target, loading_indicator) {
681
+ this.tag = $(a);
682
+ this.url = this.tag.href;
683
+ this.method = this.tag.readAttribute('data-method') || 'get';
684
+ this.target = target;
685
+ this.loading_indicator = loading_indicator;
686
+ this.hide_target = false;
687
+ this.position = this.tag.readAttribute('data-position');
688
+
689
+ this.tag.store('action_link', this);
690
+ },
691
+
692
+ open: function(event) {
693
+ },
694
+
695
+ insert: function(content) {
696
+ throw 'unimplemented'
697
+ },
698
+
699
+ close: function() {
700
+ this.enable();
701
+ this.adapter.remove();
702
+ if (this.hide_target) this.target.show();
703
+ },
704
+
705
+ reload: function() {
706
+ this.close();
707
+ this.open();
708
+ },
709
+
710
+ get_new_adapter_id: function() {
711
+ var id = 'adapter_';
712
+ var i = 0;
713
+ while ($(id + i)) i++;
714
+ return id + i;
715
+ },
716
+
717
+ enable: function() {
718
+ return this.tag.removeClassName('disabled');
719
+ },
720
+
721
+ disable: function() {
722
+ return this.tag.addClassName('disabled');
723
+ },
724
+
725
+ is_disabled: function() {
726
+ return this.tag.hasClassName('disabled');
727
+ },
728
+
729
+ scaffold_id: function() {
730
+ return this.tag.up('div.active-scaffold').readAttribute('id');
731
+ },
732
+
733
+ scaffold: function() {
734
+ return this.tag.up('div.active-scaffold');
735
+ },
736
+
737
+ update_flash_messages: function(messages) {
738
+ message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages'));
739
+ if (message_node) message_node.update(messages);
740
+ },
741
+
742
+ set_adapter: function(element) {
743
+ this.adapter = element;
744
+ this.adapter.addClassName('as_adapter');
745
+ this.adapter.store('action_link', this);
746
+ }
747
+ });
748
+
749
+ /**
750
+ * Concrete classes for record actions
751
+ */
752
+ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, {
753
+ instantiate_link: function(link) {
754
+ var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
755
+ if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh');
756
+
757
+ if (l.position) {
758
+ l.url = l.url.append_params({adapter: '_list_inline_adapter'});
759
+ l.tag.href = l.url;
760
+ }
761
+ l.set = this;
762
+ return l;
763
+ }
764
+ });
765
+
766
+ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, {
767
+ close_previous_adapter: function() {
768
+ this.set.links.each(function(item) {
769
+ if (item.url != this.url && item.is_disabled() && item.adapter) {
770
+ item.enable();
771
+ item.adapter.remove();
772
+ }
773
+ }.bind(this));
774
+ },
775
+
776
+ insert: function(content) {
777
+ this.close_previous_adapter();
778
+
779
+ if (this.position == 'replace') {
780
+ this.position = 'after';
781
+ this.hide_target = true;
782
+ }
783
+
784
+ if (this.position == 'after') {
785
+ this.target.insert({after:content});
786
+ this.set_adapter(this.target.next());
787
+ }
788
+ else if (this.position == 'before') {
789
+ this.target.insert({before:content});
790
+ this.set_adapter(this.target.previous());
791
+ }
792
+ else {
793
+ return false;
794
+ }
795
+ this.adapter.down('td').down().highlight();
796
+ },
797
+
798
+ close: function($super, refreshed_content) {
799
+ if (refreshed_content) {
800
+ ActiveScaffold.update_row(this.target, refreshed_content);
801
+ }
802
+ $super();
803
+ },
804
+
805
+ enable: function() {
806
+ this.set.links.each(function(item) {
807
+ if (item.url != this.url) return;
808
+ item.tag.removeClassName('disabled');
809
+ }.bind(this));
810
+ },
811
+
812
+ disable: function() {
813
+ this.set.links.each(function(item) {
814
+ if (item.url != this.url) return;
815
+ item.tag.addClassName('disabled');
816
+ }.bind(this));
817
+ },
818
+
819
+ set_opened: function() {
820
+ if (this.position == 'after') {
821
+ this.set_adapter(this.target.next());
822
+ }
823
+ else if (this.position == 'before') {
824
+ this.set_adapter(this.target.previous());
825
+ }
826
+ this.disable();
827
+ }
828
+ });
829
+
830
+ /**
831
+ * Concrete classes for table actions
832
+ */
833
+ ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, {
834
+ instantiate_link: function(link) {
835
+ var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator);
836
+ if (l.position) {
837
+ l.url = l.url.append_params({adapter: '_list_inline_adapter'});
838
+ l.tag.href = l.url;
839
+ }
840
+ return l;
841
+ }
842
+ });
843
+
844
+ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, {
845
+ insert: function(content) {
846
+ if (this.position == 'top') {
847
+ this.target.insert({top:content});
848
+ this.set_adapter(this.target.immediateDescendants().first());
849
+ }
850
+ else {
851
+ throw 'Unknown position "' + this.position + '"'
852
+ }
853
+ this.adapter.down('td').down().highlight();
854
+ }
855
+ });
856
+
857
+ if (Ajax.InPlaceEditor) {
858
+ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, {
859
+ initialize: function($super, element, url, options) {
860
+ $super(element, url, options);
861
+ if (this._originalBackground == 'transparent') {
862
+ this._originalBackground = null;
863
+ }
864
+ },
865
+
866
+ setFieldFromAjax: function(url, options) {
867
+ var ipe = this;
868
+ $(ipe._controls.editor).remove();
869
+ new Ajax.Request(url, {
870
+ method: 'get',
871
+ onComplete: function(response) {
872
+ ipe._form.insert({top: response.responseText});
873
+ if (options.plural) {
874
+ ipe._form.getElements().each(function(el) {
875
+ if (el.type != "submit" && el.type != "image") {
876
+ el.name = ipe.options.paramName + '[]';
877
+ el.className = 'editor_field';
878
+ }
879
+ });
880
+ } else {
881
+ var fld = ipe._form.findFirstElement();
882
+ fld.name = ipe.options.paramName;
883
+ fld.className = 'editor_field';
884
+ if (ipe.options.submitOnBlur)
885
+ fld.onblur = ipe._boundSubmitHandler;
886
+ ipe._controls.editor = fld;
887
+ }
888
+ }
889
+ });
890
+ },
891
+
892
+ clonePatternField: function() {
893
+ var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector);
894
+ if (patternNodes.editNode == null) {
895
+ alert('did not find any matching node for ' + this.options.editFieldSelector);
896
+ return;
897
+ }
898
+
899
+ var fld = patternNodes.editNode.cloneNode(true);
900
+ if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix;
901
+ fld.name = this.options.paramName;
902
+ fld.className = 'editor_field';
903
+ this.setValue(fld, this._controls.editor.value);
904
+ if (this.options.submitOnBlur)
905
+ fld.onblur = this._boundSubmitHandler;
906
+ $(this._controls.editor).remove();
907
+ this._controls.editor = fld;
908
+ this._form.appendChild(this._controls.editor);
909
+
910
+ $A(patternNodes.additionalNodes).each(function(node) {
911
+ var patternNode = node.cloneNode(true);
912
+ if (patternNode.id.length > 0) {
913
+ patternNode.id = patternNode.id + this.options.nodeIdSuffix;
914
+ }
915
+ this._form.appendChild(patternNode);
916
+ }.bind(this));
917
+ },
918
+
919
+ getPatternNodes: function(inplacePatternSelector) {
920
+ var nodes = {editNode: null, additionalNodes: []};
921
+ var selectedNodes = $$(inplacePatternSelector);
922
+ var firstNode = selectedNodes.first();
923
+
924
+ if (typeof(firstNode) !== 'undefined') {
925
+ // AS inplace_edit_control_container -> we have to select all child nodes
926
+ // Workaround for ie which does not support css > selector
927
+ if (firstNode.className.indexOf('as_inplace_pattern') !== -1) {
928
+ selectedNodes = firstNode.childElements();
929
+ }
930
+ nodes.editNode = selectedNodes.first();
931
+ selectedNodes.shift();
932
+ nodes.additionalNodes = selectedNodes;
933
+ }
934
+ return nodes;
935
+ },
936
+
937
+ setValue: function(editField, textValue) {
938
+ var function_name = 'setValueFor' + editField.nodeName.toLowerCase();
939
+ if (typeof(this[function_name]) == 'function') {
940
+ this[function_name](editField, textValue);
941
+ } else {
942
+ editField.value = textValue;
943
+ }
944
+ },
945
+
946
+ setValueForselect: function(editField, textValue) {
947
+ var len = editField.options.length;
948
+ var i = 0;
949
+ while (i < len && editField.options[i].text != textValue) {
950
+ i++;
951
+ }
952
+ if (i < len) {
953
+ editField.value = editField.options[i].value
954
+ }
955
+ }
956
+ });
957
+ }