active_scaffold 3.0.26 → 3.1.3

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