active_scaffold 3.2.18 → 3.2.19

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