active_scaffold 3.4.17 → 3.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +12 -1
  3. data/README.md +8 -4
  4. data/app/assets/javascripts/jquery/active_scaffold.js +82 -67
  5. data/app/assets/stylesheets/active_scaffold.scss +1 -1
  6. data/app/assets/stylesheets/active_scaffold_colors.scss +1 -1
  7. data/app/assets/stylesheets/blue-theme.css +1 -1
  8. data/app/views/active_scaffold_overrides/_form_association.html.erb +3 -3
  9. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +3 -3
  10. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  11. data/lib/active_scaffold.rb +16 -16
  12. data/lib/active_scaffold/actions/common_search.rb +13 -11
  13. data/lib/active_scaffold/actions/core.rb +85 -78
  14. data/lib/active_scaffold/actions/create.rb +29 -28
  15. data/lib/active_scaffold/actions/delete.rb +17 -17
  16. data/lib/active_scaffold/actions/field_search.rb +18 -19
  17. data/lib/active_scaffold/actions/list.rb +30 -22
  18. data/lib/active_scaffold/actions/mark.rb +1 -1
  19. data/lib/active_scaffold/actions/nested.rb +78 -65
  20. data/lib/active_scaffold/actions/search.rb +13 -10
  21. data/lib/active_scaffold/actions/show.rb +10 -6
  22. data/lib/active_scaffold/actions/subform.rb +1 -2
  23. data/lib/active_scaffold/actions/update.rb +39 -31
  24. data/lib/active_scaffold/active_record_permissions.rb +14 -15
  25. data/lib/active_scaffold/attribute_params.rb +42 -43
  26. data/lib/active_scaffold/bridges.rb +22 -12
  27. data/lib/active_scaffold/bridges/ancestry.rb +1 -1
  28. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +6 -6
  29. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  30. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +12 -13
  31. data/lib/active_scaffold/bridges/calendar_date_select.rb +5 -5
  32. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +17 -20
  33. data/lib/active_scaffold/bridges/cancan.rb +1 -1
  34. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +8 -9
  35. data/lib/active_scaffold/bridges/carrierwave.rb +4 -4
  36. data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +9 -8
  37. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +11 -10
  38. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +7 -6
  39. data/lib/active_scaffold/bridges/chosen.rb +1 -1
  40. data/lib/active_scaffold/bridges/chosen/helpers.rb +4 -4
  41. data/lib/active_scaffold/bridges/country_helper.rb +1 -1
  42. data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +259 -260
  43. data/lib/active_scaffold/bridges/date_picker.rb +2 -2
  44. data/lib/active_scaffold/bridges/date_picker/ext.rb +9 -11
  45. data/lib/active_scaffold/bridges/date_picker/helper.rb +61 -67
  46. data/lib/active_scaffold/bridges/dragonfly.rb +4 -4
  47. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +9 -8
  48. data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +11 -10
  49. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +6 -5
  50. data/lib/active_scaffold/bridges/file_column.rb +5 -5
  51. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +20 -23
  52. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +20 -23
  53. data/lib/active_scaffold/bridges/file_column/form_ui.rb +13 -14
  54. data/lib/active_scaffold/bridges/file_column/list_ui.rb +7 -8
  55. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +18 -22
  56. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +5 -4
  57. data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +2 -10
  58. data/lib/active_scaffold/bridges/paper_trail.rb +7 -5
  59. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +4 -3
  60. data/lib/active_scaffold/bridges/paperclip.rb +5 -5
  61. data/lib/active_scaffold/bridges/paperclip/form_ui.rb +11 -10
  62. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +6 -5
  63. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +10 -9
  64. data/lib/active_scaffold/bridges/record_select.rb +1 -1
  65. data/lib/active_scaffold/bridges/record_select/helpers.rb +28 -28
  66. data/lib/active_scaffold/bridges/semantic_attributes.rb +1 -1
  67. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +1 -1
  68. data/lib/active_scaffold/bridges/shared/date_bridge.rb +58 -52
  69. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -2
  70. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -3
  71. data/lib/active_scaffold/config/base.rb +9 -10
  72. data/lib/active_scaffold/config/core.rb +24 -29
  73. data/lib/active_scaffold/config/create.rb +0 -1
  74. data/lib/active_scaffold/config/field_search.rb +8 -10
  75. data/lib/active_scaffold/config/form.rb +5 -5
  76. data/lib/active_scaffold/config/list.rb +21 -20
  77. data/lib/active_scaffold/config/mark.rb +3 -3
  78. data/lib/active_scaffold/config/nested.rb +11 -10
  79. data/lib/active_scaffold/config/search.rb +2 -3
  80. data/lib/active_scaffold/config/show.rb +1 -1
  81. data/lib/active_scaffold/config/update.rb +1 -2
  82. data/lib/active_scaffold/configurable.rb +9 -11
  83. data/lib/active_scaffold/constraints.rb +9 -8
  84. data/lib/active_scaffold/core.rb +72 -84
  85. data/lib/active_scaffold/data_structures/action_columns.rb +26 -25
  86. data/lib/active_scaffold/data_structures/action_link.rb +43 -43
  87. data/lib/active_scaffold/data_structures/action_links.rb +17 -15
  88. data/lib/active_scaffold/data_structures/actions.rb +5 -5
  89. data/lib/active_scaffold/data_structures/bridge.rb +6 -3
  90. data/lib/active_scaffold/data_structures/column.rb +110 -89
  91. data/lib/active_scaffold/data_structures/columns.rb +3 -3
  92. data/lib/active_scaffold/data_structures/error_message.rb +4 -6
  93. data/lib/active_scaffold/data_structures/nested_info.rb +43 -48
  94. data/lib/active_scaffold/data_structures/set.rb +7 -8
  95. data/lib/active_scaffold/data_structures/sorting.rb +38 -33
  96. data/lib/active_scaffold/delayed_setup.rb +5 -6
  97. data/lib/active_scaffold/engine.rb +4 -4
  98. data/lib/active_scaffold/extensions/action_controller_rendering.rb +3 -4
  99. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  100. data/lib/active_scaffold/extensions/action_view_rendering.rb +5 -6
  101. data/lib/active_scaffold/extensions/left_outer_joins.rb +11 -11
  102. data/lib/active_scaffold/extensions/localize.rb +1 -1
  103. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  104. data/lib/active_scaffold/extensions/paginator_extensions.rb +2 -5
  105. data/lib/active_scaffold/extensions/reverse_associations.rb +13 -13
  106. data/lib/active_scaffold/extensions/routing_mapper.rb +9 -9
  107. data/lib/active_scaffold/extensions/unsaved_associated.rb +9 -9
  108. data/lib/active_scaffold/finder.rb +90 -93
  109. data/lib/active_scaffold/helpers/association_helpers.rb +5 -5
  110. data/lib/active_scaffold/helpers/controller_helpers.rb +22 -19
  111. data/lib/active_scaffold/helpers/form_column_helpers.rb +115 -105
  112. data/lib/active_scaffold/helpers/human_condition_helpers.rb +62 -35
  113. data/lib/active_scaffold/helpers/id_helpers.rb +6 -6
  114. data/lib/active_scaffold/helpers/list_column_helpers.rb +89 -94
  115. data/lib/active_scaffold/helpers/pagination_helpers.rb +9 -9
  116. data/lib/active_scaffold/helpers/search_column_helpers.rb +47 -44
  117. data/lib/active_scaffold/helpers/show_column_helpers.rb +2 -2
  118. data/lib/active_scaffold/helpers/view_helpers.rb +86 -91
  119. data/lib/active_scaffold/marked_model.rb +10 -10
  120. data/lib/active_scaffold/paginator.rb +30 -34
  121. data/lib/active_scaffold/responds_to_parent.rb +27 -28
  122. data/lib/active_scaffold/tableless.rb +20 -15
  123. data/lib/active_scaffold/version.rb +1 -1
  124. data/lib/generators/active_scaffold/active_scaffold_generator.rb +8 -8
  125. data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +9 -9
  126. data/shoulda_macros/macros.rb +27 -22
  127. data/test/bridges/bridge_test.rb +38 -29
  128. data/test/bridges/date_picker_test.rb +1 -1
  129. data/test/bridges/paper_trail_test.rb +17 -0
  130. data/test/bridges/paperclip_test.rb +3 -2
  131. data/test/bridges/tiny_mce_test.rb +5 -2
  132. data/test/company.rb +25 -30
  133. data/test/config/base_test.rb +1 -1
  134. data/test/config/core_test.rb +9 -9
  135. data/test/config/create_test.rb +14 -8
  136. data/test/config/delete_test.rb +4 -4
  137. data/test/config/field_search_test.rb +6 -6
  138. data/test/config/list_test.rb +16 -16
  139. data/test/config/nested_test.rb +4 -4
  140. data/test/config/search_test.rb +8 -8
  141. data/test/config/show_test.rb +6 -6
  142. data/test/config/subform_test.rb +1 -1
  143. data/test/config/update_test.rb +5 -5
  144. data/test/const_mocker.rb +4 -4
  145. data/test/data_structures/action_columns_test.rb +4 -5
  146. data/test/data_structures/action_link_test.rb +1 -0
  147. data/test/data_structures/action_links_test.rb +5 -5
  148. data/test/data_structures/column_test.rb +9 -9
  149. data/test/data_structures/columns_test.rb +2 -2
  150. data/test/data_structures/error_message_test.rb +4 -5
  151. data/test/data_structures/set_test.rb +1 -2
  152. data/test/data_structures/sorting_test.rb +10 -10
  153. data/test/data_structures/validation_reflection_test.rb +8 -0
  154. data/test/extensions/routing_mapper_test.rb +2 -2
  155. data/test/helpers/list_column_helpers_test.rb +3 -2
  156. data/test/helpers/pagination_helpers_test.rb +5 -4
  157. data/test/helpers/search_column_helpers_test.rb +1 -1
  158. data/test/misc/active_record_permissions_test.rb +63 -50
  159. data/test/misc/attribute_params_test.rb +28 -26
  160. data/test/misc/calculation_test.rb +10 -3
  161. data/test/misc/configurable_test.rb +12 -13
  162. data/test/misc/constraints_test.rb +6 -6
  163. data/test/misc/convert_numbers_format_test.rb +7 -6
  164. data/test/misc/finder_test.rb +17 -12
  165. data/test/misc/lang_test.rb +3 -4
  166. data/test/misc/tableless_test.rb +2 -3
  167. data/test/mock_app/app/controllers/addresses_controller.rb +1 -1
  168. data/test/mock_app/app/controllers/buildings_controller.rb +1 -1
  169. data/test/mock_app/app/controllers/cars_controller.rb +1 -1
  170. data/test/mock_app/app/controllers/contacts_controller.rb +1 -1
  171. data/test/mock_app/app/controllers/people_controller.rb +1 -1
  172. data/test/mock_app/app/models/file_model.rb +2 -2
  173. data/test/mock_app/app/models/person.rb +1 -1
  174. data/test/mock_app/config/application.rb +3 -3
  175. data/test/mock_app/config/boot.rb +1 -1
  176. data/test/mock_app/config/environment.rb +1 -0
  177. data/test/mock_app/config/environments/development.rb +0 -1
  178. data/test/mock_app/config/environments/production.rb +1 -1
  179. data/test/mock_app/db/schema.rb +14 -15
  180. data/test/model_stub.rb +13 -16
  181. data/test/run_all.rb +5 -7
  182. data/test/test_helper.rb +12 -9
  183. metadata +19 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b1be864fa28fa3a7caca50a268de1ecd1070426
4
- data.tar.gz: db83b56413734d2fdc7aab465efa47b89dd3edfe
3
+ metadata.gz: e5240d9cb10131fb335065071e8a786e745e9bce
4
+ data.tar.gz: a1493ba2efd6d6a58deaece8b630b6ba4a729e3a
5
5
  SHA512:
6
- metadata.gz: f98c93d4d03d4347e73dd18793629c1bc8cb16ee6b0ee900a130b86f9c7e27f6aec751d67cf2abd255d74a087bab3af16f54466ddcbf17d2ec5cab568b947171
7
- data.tar.gz: 36e97b6c0e09d2aecb3f27d63690e0bcbea16239d371ccd6711820de75ab059b43796e2a3af63b69c206143e25e7efc9e43d3cbc374ea6ba7743c9f0fb8181c7
6
+ metadata.gz: 8b846bb4dc8ac8bbe018429b8b7fcd8a3ba77dc0a2edf68fd128fb009f335c82412ad772594e34197efffed7d420ce7b9f8962b5bc9f2ae54e7d466cd23ba754
7
+ data.tar.gz: e901b88edfec58dae9bbc69eba15a3457ca19aac7faa66c213fcfeab87f8bd2ede76c136f27b429020e6e5bcffc8d3b60f3dc80d43ce1e0504e62a058e9ed1e9
data/CHANGELOG CHANGED
@@ -1,3 +1,14 @@
1
+ = 3.4.18
2
+ - Fix paper_trail bridge on development
3
+ - Allow to set :data hash in :html_options for action links
4
+ - unscope(:order) in calculate_query (for rails >= 4)
5
+ - clean code and follow ruby style guide
6
+ - deny_access (rescue method for ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed) render with status :forbidden (403) instead of 401
7
+ - allow to load nested scaffold with nested through associations, even with inplace edit enabled
8
+ - disable create on nested through associations
9
+ - Allow to config live_search delay with ActiveScaffold.js_config
10
+ - Warn when form is changed (ignores search forms), this featured must be enabled with ActiveScaffold.js_config[:warn_changes]
11
+
1
12
  = 3.4.17
2
13
  - Fix deprecation warning "Extra .css in SCSS file is unnecessary"
3
14
  - Improve support for namespaced models on namespaced controllers with different namespace
@@ -271,7 +282,7 @@
271
282
  - Add some classes to forms to improve CSS customization
272
283
  - Fix nested links for STI controllers with common configuration in a base controller
273
284
  - Fix adding routes twice in active_scaffold generator
274
- - Restore old behavior for action_link's security_method, ignore_method already hides the link
285
+ - Restore old behavior for action_link's security_method, ignore_method already hides the link
275
286
  - Add data-cancel-refresh to action links, so nested scaffold's behaviour can be applied to other action links and when adapter is closed row will be refreshed.
276
287
  - fix support for tableless models in rails >= 3.2.5
277
288
 
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Overview
2
2
  ========
3
- [![travis tests](https://travis-ci.org/activescaffold/active_scaffold.png)](https://travis-ci.org/activescaffold/active_scaffold)
3
+ [![Build status](https://travis-ci.org/activescaffold/active_scaffold.svg?branch=master)](https://travis-ci.org/activescaffold/active_scaffold)
4
+ [![Code Climate](https://codeclimate.com/github/activescaffold/active_scaffold/badges/gpa.svg)](https://codeclimate.com/github/activescaffold/active_scaffold)
5
+ [![Test Coverage](https://codeclimate.com/github/activescaffold/active_scaffold/badges/coverage.svg)](https://codeclimate.com/github/activescaffold/active_scaffold)
6
+ [![Dependency Status](https://gemnasium.com/activescaffold/active_scaffold.svg)](https://gemnasium.com/activescaffold/active_scaffold)
7
+ [![Gem Version](https://badge.fury.io/rb/active_scaffold.svg)](https://badge.fury.io/rb/active_scaffold)
4
8
 
5
9
  ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, read, update, delete) operations for Rails applications. It offers additonal features including searching, pagination & layout control. Rails 3.2 and 4.x are supported, ruby >= 1.9 required. For rails 4 is recommended >= 4.0.5.
6
10
 
@@ -49,7 +53,7 @@ Credits
49
53
  -------
50
54
  ActiveScaffold grew out of a project named Ajaxscaffold dating back to 2006. It has had numerous contributors including:
51
55
 
52
- ActiveScaffold Gem/Plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com)
56
+ ActiveScaffold Gem/Plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@programatica.es)
53
57
 
54
58
  Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu)
55
59
  http://codinginparadise.org
@@ -60,8 +64,8 @@ http://adamv.com/dev/javascript/querystring
60
64
  Uses Paginator by Bruce Williams
61
65
  http://paginator.rubyforge.org/
62
66
 
63
- Supports RecordSelect by Lance Ivy
64
- http://code.google.com/p/recordselect/
67
+ Supports RecordSelect by Lance Ivy and Sergio Cambra
68
+ http://github.com/scambra/recordselect/
65
69
 
66
70
 
67
71
  License
@@ -47,7 +47,7 @@ jQuery(document).ready(function($) {
47
47
  }
48
48
  return true;
49
49
  });
50
-
50
+
51
51
  jQuery(document).on('ajax:complete', 'form.as_form', function(event) {
52
52
  var as_form = jQuery(this).closest("form");
53
53
  if (as_form.data('loading') == true) {
@@ -96,7 +96,7 @@ jQuery(document).ready(function($) {
96
96
  action_link.enable();
97
97
  }
98
98
  jQuery(this).trigger('as:action_success', action_link);
99
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
99
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
100
100
  }
101
101
  return true;
102
102
  });
@@ -110,8 +110,8 @@ jQuery(document).ready(function($) {
110
110
  });
111
111
  jQuery(document).on('ajax:before', 'a.as_cancel', function(event) {
112
112
  var as_cancel = jQuery(this);
113
- var action_link = ActiveScaffold.find_action_link(as_cancel);
114
-
113
+ var action_link = ActiveScaffold.find_action_link(as_cancel);
114
+
115
115
  if (action_link) {
116
116
  var cancel_url = as_cancel.attr('href');
117
117
  var refresh_data = action_link.tag.data('cancel-refresh') || as_cancel.data('refresh');
@@ -199,7 +199,7 @@ jQuery(document).ready(function($) {
199
199
  });
200
200
  jQuery(document).on('ajax:complete', '.action_group.dyn > ul a', function(event) {
201
201
  var action_link = ActiveScaffold.find_action_link(event.target);
202
- if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
202
+ if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
203
203
  jQuery(event.target).closest('.action_group.dyn > ul').remove();
204
204
  });
205
205
 
@@ -240,14 +240,14 @@ jQuery(document).ready(function($) {
240
240
  ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), id);
241
241
  return true;
242
242
  });
243
-
243
+
244
244
  jQuery(document).on('change', 'select.as_search_range_option', function(event) {
245
245
  var element = jQuery(this);
246
246
  ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between'));
247
247
  ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric'));
248
248
  return true;
249
249
  });
250
-
250
+
251
251
  jQuery(document).on('change', 'select.as_search_date_time_option', function(event) {
252
252
  var element = jQuery(this);
253
253
  ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric'));
@@ -261,7 +261,7 @@ jQuery(document).ready(function($) {
261
261
  ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'hide' : 'show'](jQuery(this).next().next());
262
262
  return true;
263
263
  });
264
-
264
+
265
265
  jQuery(document).on('click', '.active-scaffold .sub-form a.destroy', function(event) {
266
266
  event.preventDefault();
267
267
  ActiveScaffold.delete_subform_record($(this).data('delete-id'));
@@ -289,13 +289,14 @@ jQuery(document).ready(function($) {
289
289
  ActiveScaffold.hide(jQuery(this).closest('.message'));
290
290
  e.preventDefault();
291
291
  });
292
-
292
+
293
293
  /* setup some elements on page/form load */
294
294
  ActiveScaffold.load_embedded(document);
295
295
  ActiveScaffold.enable_js_form_buttons(document);
296
296
  ActiveScaffold.live_search(document);
297
297
  ActiveScaffold.auto_paginate(document);
298
298
  ActiveScaffold.draggable_lists('.draggable-lists', document);
299
+ if (ActiveScaffold.warn_changes) ActiveScaffold.setup_warn_changes();
299
300
  jQuery(document).on('as:element_updated', function(e) {
300
301
  ActiveScaffold.load_embedded(e.target);
301
302
  ActiveScaffold.enable_js_form_buttons(e.target);
@@ -320,17 +321,17 @@ jQuery(document).ready(function($) {
320
321
 
321
322
  // The base Class implementation (does nothing)
322
323
  this.Class = function(){};
323
-
324
+
324
325
  // Create a new Class that inherits from this class
325
326
  Class.extend = function(prop) {
326
327
  var _super = this.prototype;
327
-
328
+
328
329
  // Instantiate a base class (but only create the instance,
329
330
  // don't run the init constructor)
330
331
  initializing = true;
331
332
  var prototype = new this();
332
333
  initializing = false;
333
-
334
+
334
335
  // Copy the properties over onto the new prototype
335
336
  for (var name in prop) {
336
337
  // Check if we're overwriting an existing function
@@ -339,38 +340,38 @@ jQuery(document).ready(function($) {
339
340
  (function(name, fn){
340
341
  return function() {
341
342
  var tmp = this._super;
342
-
343
+
343
344
  // Add a new ._super() method that is the same method
344
345
  // but on the super-class
345
346
  this._super = _super[name];
346
-
347
+
347
348
  // The method only need to be bound temporarily, so we
348
349
  // remove it when we're done executing
349
- var ret = fn.apply(this, arguments);
350
+ var ret = fn.apply(this, arguments);
350
351
  this._super = tmp;
351
-
352
+
352
353
  return ret;
353
354
  };
354
355
  })(name, prop[name]) :
355
356
  prop[name];
356
357
  }
357
-
358
+
358
359
  // The dummy class constructor
359
360
  function Class() {
360
361
  // All construction is actually done in the init method
361
362
  if ( !initializing && this.init )
362
363
  this.init.apply(this, arguments);
363
364
  }
364
-
365
+
365
366
  // Populate our constructed prototype object
366
367
  Class.prototype = prototype;
367
-
368
+
368
369
  // Enforce the constructor to be what we expect
369
370
  Class.constructor = Class;
370
371
 
371
372
  // And make this class extendable
372
373
  Class.extend = arguments.callee;
373
-
374
+
374
375
  return Class;
375
376
  };
376
377
  })();
@@ -378,9 +379,9 @@ jQuery(document).ready(function($) {
378
379
  /*
379
380
  $ delayed observer
380
381
  (c) 2007 - Maxime Haineault (max@centdessin.com)
381
-
382
+
382
383
  Special thanks to Stephen Goguen & Tane Piper.
383
-
384
+
384
385
  Slight modifications by Elliot Winkler
385
386
  */
386
387
 
@@ -422,7 +423,7 @@ var ActiveScaffold = {
422
423
  live_search: function(element) {
423
424
  jQuery('form.search.live input[type=search]', element).delayedObserver(function() {
424
425
  jQuery(this).parent().trigger("submit");
425
- }, 0.5);
426
+ }, ActiveScaffold.config.live_search_delay || 0.5);
426
427
  },
427
428
  auto_paginate: function(element) {
428
429
  var paginate_link = jQuery('.active-scaffold-pagination.auto-paginate a:first', element);
@@ -453,7 +454,7 @@ var ActiveScaffold = {
453
454
  stripe: function(tbody_id) {
454
455
  var even = false;
455
456
  var rows = this.records_for(tbody_id);
456
-
457
+
457
458
  rows.each(function (index, row_node) {
458
459
  row = jQuery(row_node);
459
460
  if (row_node.tagName != 'SCRIPT'
@@ -466,7 +467,7 @@ var ActiveScaffold = {
466
467
  else row.removeClass("even-record");
467
468
 
468
469
  even = !even;
469
- }
470
+ }
470
471
  });
471
472
  },
472
473
  hide_empty_message: function(tbody) {
@@ -497,7 +498,7 @@ var ActiveScaffold = {
497
498
  },
498
499
  decrement_record_count: function(scaffold) {
499
500
  // decrement the last record count, firsts record count are in nested lists
500
- if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
501
+ if (typeof(scaffold) == 'string') scaffold = '#' + scaffold;
501
502
  scaffold = jQuery(scaffold);
502
503
  count = scaffold.find('span.active-scaffold-records').last();
503
504
  if (count) count.html(parseInt(count.html(), 10) - 1);
@@ -512,7 +513,7 @@ var ActiveScaffold = {
512
513
  update_row: function(row, html) {
513
514
  var even_row = false;
514
515
  var replaced = null;
515
- if (typeof(row) == 'string') row = '#' + row;
516
+ if (typeof(row) == 'string') row = '#' + row;
516
517
  row = jQuery(row);
517
518
  if (row.hasClass('even-record')) even_row = true;
518
519
 
@@ -522,9 +523,9 @@ var ActiveScaffold = {
522
523
  ActiveScaffold.highlight(replaced);
523
524
  }
524
525
  },
525
-
526
+
526
527
  replace: function(element, html) {
527
- if (typeof(element) == 'string') element = '#' + element;
528
+ if (typeof(element) == 'string') element = '#' + element;
528
529
  element = jQuery(element);
529
530
  var new_element = typeof(html) == 'string' ? jQuery.parseHTML(jQuery.trim(html), true) : html;
530
531
  new_element = jQuery(new_element);
@@ -534,9 +535,9 @@ var ActiveScaffold = {
534
535
  return new_element;
535
536
  } else return null;
536
537
  },
537
-
538
+
538
539
  replace_html: function(element, html) {
539
- if (typeof(element) == 'string') element = '#' + element;
540
+ if (typeof(element) == 'string') element = '#' + element;
540
541
  element = jQuery(element);
541
542
  if (element.length) {
542
543
  element.html(html);
@@ -546,15 +547,15 @@ var ActiveScaffold = {
546
547
  },
547
548
 
548
549
  append: function(element, html) {
549
- if (typeof(element) == 'string') element = '#' + element;
550
+ if (typeof(element) == 'string') element = '#' + element;
550
551
  element = jQuery(element);
551
552
  element.append(html);
552
553
  element.trigger('as:element_updated');
553
554
  return element;
554
555
  },
555
-
556
+
556
557
  remove: function(element, callback) {
557
- if (typeof(element) == 'string') element = '#' + element;
558
+ if (typeof(element) == 'string') element = '#' + element;
558
559
  jQuery(element).trigger('as:element_removed').remove();
559
560
  if (callback) callback();
560
561
  },
@@ -564,22 +565,22 @@ var ActiveScaffold = {
564
565
  this.replace_html(jQuery(element), value);
565
566
  jQuery(element).closest('td')[empty ? 'addClass' : 'removeClass']('empty');
566
567
  },
567
-
568
+
568
569
  hide: function(element) {
569
570
  if (typeof(element) == 'string') element = '#' + element;
570
571
  jQuery(element).hide();
571
572
  },
572
-
573
+
573
574
  show: function(element) {
574
575
  if (typeof(element) == 'string') element = '#' + element;
575
576
  jQuery(element).show();
576
577
  },
577
-
578
+
578
579
  reset_form: function(element) {
579
580
  if (typeof(element) == 'string') element = '#' + element;
580
581
  jQuery(element).get(0).reset();
581
582
  },
582
-
583
+
583
584
  disable_form: function(as_form, skip_loading_indicator) {
584
585
  if (typeof(as_form) == 'string') as_form = '#' + as_form;
585
586
  as_form = jQuery(as_form)
@@ -591,7 +592,7 @@ var ActiveScaffold = {
591
592
  // data-remote-disabled attr instead of set data because is used to in selector later
592
593
  jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled').attr('data-remove-disabled', true);
593
594
  },
594
-
595
+
595
596
  enable_form: function(as_form, skip_loading_indicator) {
596
597
  if (typeof(as_form) == 'string') as_form = '#' + as_form;
597
598
  as_form = jQuery(as_form)
@@ -601,19 +602,19 @@ var ActiveScaffold = {
601
602
  jQuery('.sub-form a.destroy.disabled', as_form).removeClass('disabled');
602
603
  if (jQuery.fn.droppable) jQuery('.draggable-list', as_form).sortable('enable');
603
604
  jQuery("input[data-remove-disabled],select[data-remove-disabled],textarea[data-remove-disabled]", as_form).removeAttr('disabled data-remove-disabled');
604
- },
605
-
605
+ },
606
+
606
607
  focus_first_element_of_form: function(form_element, form_selector) {
607
608
  if (typeof(form_element) == 'string') form_element = '#' + form_element;
608
609
  if (typeof(form_selector) == 'undefined') form_selector = jQuery(form_element).is('form') ? '' : 'form ';
609
610
  jQuery(form_selector + ":input:visible:first", jQuery(form_element)).focus();
610
611
  },
611
-
612
+
612
613
  create_record_row: function(active_scaffold_id, html, options) {
613
614
  if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id;
614
615
  tbody = jQuery(active_scaffold_id).find('tbody.records').first();
615
616
  var new_row;
616
-
617
+
617
618
  if (options.insert_at == 'top') {
618
619
  tbody.prepend(html);
619
620
  new_row = tbody.children('tr.record:first-child');
@@ -644,24 +645,24 @@ var ActiveScaffold = {
644
645
  this.highlight(new_row);
645
646
  new_row.trigger('as:element_created');
646
647
  },
647
-
648
+
648
649
  create_record_row_from_url: function(action_link, url, options) {
649
650
  jQuery.get(url, function(row) {
650
651
  ActiveScaffold.create_record_row(action_link.scaffold(), row, options);
651
652
  action_link.close();
652
653
  });
653
654
  },
654
-
655
+
655
656
  delete_record_row: function(row, page_reload_url) {
656
657
  if (typeof(row) == 'string') row = '#' + row;
657
658
  row = jQuery(row);
658
659
  var tbody = row.closest('tbody.records');
659
-
660
+
660
661
  row.find('a.disabled').each(function() {;
661
662
  var action_link = ActiveScaffold.ActionLink.get(this);
662
663
  if (action_link) action_link.close();
663
664
  });
664
-
665
+
665
666
  ActiveScaffold.remove(row, function() {
666
667
  ActiveScaffold.stripe(tbody);
667
668
  ActiveScaffold.decrement_record_count(tbody.closest('div.active-scaffold'));
@@ -685,7 +686,7 @@ var ActiveScaffold = {
685
686
  if (xhr) server_error.find('.error-500')[xhr.status < 500 ? 'hide' : 'show']();
686
687
  ActiveScaffold.scroll_to(server_error, ActiveScaffold.config.scroll_on_close == 'checkInViewport');
687
688
  },
688
-
689
+
689
690
  find_action_link: function(element) {
690
691
  if (typeof(element) == 'string') element = '#' + element;
691
692
  element = jQuery(element);
@@ -704,7 +705,7 @@ var ActiveScaffold = {
704
705
  container.find('> ul').remove();
705
706
  container.append(html);
706
707
  },
707
-
708
+
708
709
  scroll_to: function(element, checkInViewport) {
709
710
  if (typeof checkInViewport == 'undefined') checkInViewport = true;
710
711
  if (typeof(element) == 'string') element = '#' + element;
@@ -715,10 +716,10 @@ var ActiveScaffold = {
715
716
  // If it's in viewport , don't scroll;
716
717
  if (form_offset + jQuery(element).height() <= docViewBottom && form_offset >= docViewTop) return;
717
718
  }
718
-
719
+
719
720
  jQuery(document).scrollTop(form_offset);
720
721
  },
721
-
722
+
722
723
  process_checkbox_inplace_edit: function(checkbox, options) {
723
724
  var checked = checkbox.is(':checked'), td = checkbox.closest('td');
724
725
  if (checked === true) options['params'] += '&value=1';
@@ -740,7 +741,7 @@ var ActiveScaffold = {
740
741
  }
741
742
  });
742
743
  },
743
-
744
+
744
745
  read_inplace_edit_heading_attributes: function(column_heading, options) {
745
746
  if (column_heading.data('ie-cancel-text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.data('ie-cancel-text') + "</button>";
746
747
  if (column_heading.data('ie-loading-text')) options.loading_text = column_heading.data('ie-loading-text');
@@ -749,21 +750,21 @@ var ActiveScaffold = {
749
750
  if (column_heading.data('ie-rows')) options.textarea_rows = column_heading.data('ie-rows');
750
751
  if (column_heading.data('ie-cols')) options.textarea_cols = column_heading.data('ie-cols');
751
752
  if (column_heading.data('ie-size')) options.text_size = column_heading.data('ie-size');
752
- },
753
-
753
+ },
754
+
754
755
  create_inplace_editor: function(span, options) {
755
756
  span.removeClass('hover');
756
757
  span.editInPlace(options);
757
758
  span.trigger('click.editInPlace');
758
759
  },
759
-
760
+
760
761
  highlight: function(element) {
761
762
  if (typeof(element) == 'string') element = jQuery('#' + element);
762
763
  if (typeof(element.effect) == 'function') {
763
764
  element.effect("highlight", jQuery.extend({}, ActiveScaffold.config.highlight), 3000);
764
765
  }
765
766
  },
766
-
767
+
767
768
  create_associated_record_form: function(element, content, options) {
768
769
  if (typeof(element) == 'string') element = '#' + element;
769
770
  var element = jQuery(element);
@@ -785,7 +786,7 @@ var ActiveScaffold = {
785
786
  ActiveScaffold.focus_first_element_of_form(content, '');
786
787
  content.trigger('as:element_created');
787
788
  },
788
-
789
+
789
790
  render_form_field: function(source, content, options) {
790
791
  if (typeof(source) == 'string') source = '#' + source;
791
792
  var source = jQuery(source);
@@ -806,7 +807,7 @@ var ActiveScaffold = {
806
807
  }
807
808
  }
808
809
  },
809
-
810
+
810
811
  record_select_onselect: function(edit_associated_url, active_scaffold_id, id){
811
812
  jQuery.ajax({
812
813
  url: edit_associated_url.replace('--ID--', id),
@@ -925,7 +926,7 @@ var ActiveScaffold = {
925
926
  }
926
927
  }
927
928
  },
928
-
929
+
929
930
  update_column: function(element, url, send_form, source_id, val, additional_params) {
930
931
  if (!element) element = jQuery('#' + source_id);
931
932
  var as_form = element.closest('form.as_form');
@@ -975,13 +976,27 @@ var ActiveScaffold = {
975
976
  }
976
977
  });
977
978
  },
978
-
979
+
979
980
  draggable_lists: function(selector_or_elements, parent) {
980
981
  var elements;
981
982
  if (!jQuery.fn.draggableLists) return;
982
983
  if (typeof(selector_or_elements) == 'string') elements = jQuery(selector_or_elements, parent);
983
984
  else elements = jQuery(selector_or_elements);
984
985
  elements.draggableLists();
986
+ },
987
+
988
+ setup_warn_changes: function() {
989
+ var need_confirm = false;
990
+ var unload_message = $('meta[name=unload-message]').val() || ActiveScaffold.config.unload_message || "Are you sure you want to navigate away? Any unsaved data will be lost.";
991
+ $(document).on('change input', '.active-scaffold form:not(.search) input, .active-scaffold form:not(.search) textarea, .active-scaffold form:not(.search) select', function() {
992
+ $(this).closest('form').addClass('need-confirm');
993
+ });
994
+ $(document).on('click', '.active-scaffold .as_cancel:not([data-remote])', function() {
995
+ $(this).closest('form').removeClass('need-confirm');
996
+ });
997
+ window.onbeforeunload = function() {
998
+ if ($('form.need-confirm').length) return unload_message;
999
+ }
985
1000
  }
986
1001
  }
987
1002
 
@@ -1010,8 +1025,8 @@ String.prototype.append_params = function(params) {
1010
1025
  for(var key in params) {
1011
1026
  if (key) url += (key + '=' + params[key] + '&');
1012
1027
  }
1013
-
1014
- // the loop leaves a comma dangling at the end of string, chop it off
1028
+
1029
+ // the loop leaves a comma dangling at the end of string, chop it off
1015
1030
  url = url.substring(0, url.length-1);
1016
1031
  return url;
1017
1032
  };
@@ -1026,7 +1041,7 @@ ActiveScaffold.Actions.Abstract = Class.extend({
1026
1041
  this.target = jQuery(target);
1027
1042
  this.loading_indicator = jQuery(loading_indicator);
1028
1043
  this.options = options;
1029
- var _this = this;
1044
+ var _this = this;
1030
1045
  this.links = jQuery.map(links, function(link) {
1031
1046
  var my_link = _this.instantiate_link(link);
1032
1047
  return my_link;
@@ -1090,7 +1105,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({
1090
1105
  open: function(event) {
1091
1106
  this.tag.click();
1092
1107
  },
1093
-
1108
+
1094
1109
  insert: function(content) {
1095
1110
  throw 'unimplemented'
1096
1111
  },
@@ -1137,7 +1152,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({
1137
1152
  scaffold: function() {
1138
1153
  return this.tag.closest('div.active-scaffold');
1139
1154
  },
1140
-
1155
+
1141
1156
  update_flash_messages: function(messages) {
1142
1157
  message_node = jQuery(this.scaffold_id().replace(/-active-scaffold/, '-messages'));
1143
1158
  if (message_node) message_node.html(messages);
@@ -1161,7 +1176,7 @@ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({
1161
1176
  var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator);
1162
1177
  var refresh = this.target.data('refresh');
1163
1178
  if (refresh) l.refresh_url = this.target.closest('.records').data('refresh-record').replace('--ID--', refresh);
1164
-
1179
+
1165
1180
  if (l.position) {
1166
1181
  l.url = l.url.append_params({adapter: '_list_inline_adapter'});
1167
1182
  l.tag.attr('href', l.url);
@@ -1238,7 +1253,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({
1238
1253
  item.tag.addClass('disabled');
1239
1254
  });
1240
1255
  },
1241
-
1256
+
1242
1257
  set_opened: function() {
1243
1258
  if (this.position == 'after') {
1244
1259
  this.set_adapter(this.target.next());