active_scaffold 3.4.8 → 3.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5de5babbd2447c2a706b2627e7e1cb09966e563
4
- data.tar.gz: 371b743005cc81c284a673ee82e9fd23048bf8e3
3
+ metadata.gz: c83a7d7ce3f57146d10cbf6134cc41c46f4753e3
4
+ data.tar.gz: 4e19dd8122bde0ded7a956146709fa981d05a9bd
5
5
  SHA512:
6
- metadata.gz: 1c3156bc03652f0b4efdfe075dd5019648ada5087474e17d49c6fdfd0bdf0e4dc1465eec783638154f22dcaa62d98eb9eeb54ce3b01b6ec04b732931bf495237
7
- data.tar.gz: 797149d0738f3e7f995bd13e367fb589e8fa9956d1954b65b90b3e15925631a763ac630227df4ffb6c5c8ebbeb6b466571874601c841eee4506dd3868abc70b5
6
+ metadata.gz: 397d444554b333a865f9c9302655a3d5519c48dcc1dd768be0317a66e94c29d4b70f087809ac4cca049a2ed295b4b53971811a1fcbd7c3e42a9536bea2b41de2
7
+ data.tar.gz: 2e5a2a8706e97af1a82f35335e55a4abc6e97c9156e3d23ef2ad093ca868c473f9f8b425ce926600a4d013b9b05d586b31e87e22b5d8b97ab726d4dceb95aaff
data/CHANGELOG CHANGED
@@ -1,4 +1,14 @@
1
- = 3.4.8 (not released yet)
1
+ = 3.4.9
2
+ - update parent data when changing a column in subform of edit form, so parent has data from form as it works in new form
3
+ - use :only and :except options from resource line on as_routes and as_association_routes, so activescaffold actions can be selected
4
+ - focus first element of subform record added
5
+ - changes on destroy:
6
+ - destroy.js.erb uses main_path_to_return to get url to reload if page empty
7
+ - delete_record_row can be called without url
8
+ - messages_id and form_selector on create, update and destroy JS views can be overrided when calling render :super
9
+ - element_row_id on list_record partial can be overrided when calling render :super with :row_id local
10
+
11
+ = 3.4.8
2
12
  - set parent data when adding new record on subform of a create form on a embedded or nested list
3
13
  - trigger ajax:* events on ajax call to render_field
4
14
 
@@ -396,7 +396,8 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
396
396
  else {
397
397
  if (el.data('timer')) { clearTimeout(el.data('timer')); }
398
398
  el.data('timer', setTimeout(function(){
399
- el.data('callback').apply(el);
399
+ var callback = el.data('callback')
400
+ if (callback) callback.apply(el);
400
401
  }, el.data('delay') * 1000));
401
402
  el.data('oldval', el.val());
402
403
  }
@@ -598,10 +599,10 @@ var ActiveScaffold = {
598
599
  jQuery("input[data-remove-disabled],select[data-remove-disabled],textarea[data-remove-disabled]", as_form).removeAttr('disabled data-remove-disabled');
599
600
  },
600
601
 
601
- focus_first_element_of_form: function(form_element) {
602
+ focus_first_element_of_form: function(form_element, form_selector) {
602
603
  if (typeof(form_element) == 'string') form_element = '#' + form_element;
603
- var form_selector = jQuery(form_element).is('form') ? '' : 'form ';
604
- jQuery(form_selector + ":input[type!=hidden]:first", jQuery(form_element)).focus();
604
+ if (typeof(form_selector) == 'undefined') form_selector = jQuery(form_element).is('form') ? '' : 'form ';
605
+ jQuery(form_selector + ":input:visible:first", jQuery(form_element)).focus();
605
606
  },
606
607
 
607
608
  create_record_row: function(active_scaffold_id, html, options) {
@@ -660,7 +661,7 @@ var ActiveScaffold = {
660
661
  ActiveScaffold.remove(row, function() {
661
662
  ActiveScaffold.stripe(tbody);
662
663
  ActiveScaffold.decrement_record_count(tbody.closest('div.active-scaffold'));
663
- ActiveScaffold.reload_if_empty(tbody, page_reload_url);
664
+ if (page_reload_url) ActiveScaffold.reload_if_empty(tbody, page_reload_url);
664
665
  });
665
666
  },
666
667
 
@@ -768,7 +769,6 @@ var ActiveScaffold = {
768
769
  var tfoot = element.children('tfoot');
769
770
  if (tfoot.length) tfoot.before(content);
770
771
  else element.append(content);
771
- content.trigger('as:element_created');
772
772
  }
773
773
  } else {
774
774
  var current = jQuery('#' + element.attr('id') + ' .sub-form-record')
@@ -776,9 +776,10 @@ var ActiveScaffold = {
776
776
  this.replace(current[0], content);
777
777
  } else {
778
778
  element.prepend(content);
779
- content.trigger('as:element_created');
780
779
  }
781
780
  }
781
+ ActiveScaffold.focus_first_element_of_form(content, '');
782
+ content.trigger('as:element_created');
782
783
  },
783
784
 
784
785
  render_form_field: function(source, content, options) {
@@ -1,11 +1,12 @@
1
1
  <%
2
2
  record = list_record if local_assigns[:list_record] # compat with render :partial :collection
3
3
  columns ||= list_columns
4
+ row_id ||= element_row_id(:action => :list, :id => record.id)
4
5
  tr_class = cycle("", "even-record") + ' ' + list_row_class(record)
5
6
  action_links ||= active_scaffold_config.action_links.member
6
7
  data_refresh ||= record.to_param
7
8
  -%>
8
- <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= data_refresh %>">
9
+ <tr class="record <%= tr_class %>" id="<%= row_id %>" data-refresh="<%= data_refresh %>">
9
10
  <% columns.each do |column| %>
10
11
  <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%>
11
12
  <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%>
@@ -1,4 +1,4 @@
1
- <% messages_id = active_scaffold_messages_id %>
1
+ <% messages_id ||= active_scaffold_messages_id %>
2
2
  <% if successful? %>
3
3
  <% if render_parent? %>
4
4
  <% if render_parent_action == :row %>
@@ -17,7 +17,11 @@
17
17
  <% elsif (active_scaffold_config.delete.refresh_list) %>
18
18
  <%= render :partial => 'refresh_list' %>
19
19
  <% else %>
20
- ActiveScaffold.delete_record_row('<%= element_row_id(:action => 'list', :id => params[:id]) %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>');
20
+ <%
21
+ url = main_path_to_return
22
+ url[:page] = [active_scaffold_config.list.user.page.to_i - 1, 1].max if url.is_a? Hash
23
+ %>
24
+ ActiveScaffold.delete_record_row('<%= element_row_id(:action => 'list', :id => params[:id]) %>', '<%= url_for(url) %>');
21
25
  <%= render :partial => 'update_calculations', :formats => [:js] %>
22
26
  <% end %>
23
27
  <% else %>
@@ -1,6 +1,6 @@
1
1
  try {
2
2
  var action_link;
3
- <% form_selector = "#{element_form_id(:action => :create)}"
3
+ <% form_selector ||= "#{element_form_id(:action => :create)}"
4
4
  insert_at ||= :top -%>
5
5
  <% if active_scaffold_config.list.always_show_create -%>
6
6
  <%= render :partial => 'update_messages' %>
@@ -1,5 +1,5 @@
1
1
  try {
2
- <% form_selector = "#{element_form_id(:action => :update, :id => @record.try(:id) || params[:id])}" %>
2
+ <% form_selector ||= "#{element_form_id(:action => :update, :id => @record.try(:id) || params[:id])}" %>
3
3
  var action_link = ActiveScaffold.find_action_link('<%= form_selector %>');
4
4
  action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>');
5
5
  <% if successful? %>
@@ -83,7 +83,7 @@ module ActiveScaffold::Actions
83
83
  @record.send "#{@column.name}=", value
84
84
  @record.id = params[:id]
85
85
  end
86
- set_parent(@record) if @record.id.nil? && params[:parent_controller] && @scope
86
+ set_parent(@record) if params[:parent_controller] && @scope
87
87
 
88
88
  after_render_field(@record, @column)
89
89
  end
@@ -98,7 +98,7 @@ module ActiveScaffold::Actions
98
98
  copy_attributes(parent_model.find(params[:parent_id]), parent) if params[:parent_id]
99
99
  parent.id = params[:parent_id]
100
100
  parent = update_record_from_params(parent, active_scaffold_config_for(parent_model).send(params[:parent_id] ? :update : :create).columns, params[:record], true) if @column.send_form_on_update_column
101
- apply_constraints_to_record(parent) if params[:parent_id]
101
+ apply_constraints_to_record(parent) unless params[:parent_id]
102
102
  if record.class.reflect_on_association(association).collection?
103
103
  record.send(association) << parent
104
104
  else
@@ -114,7 +114,7 @@ module ActiveScaffold::Actions
114
114
  attributes.each { |attr, value| dst.send :write_attribute, attr, value if orig.class.accessible_attributes.deny? attr }
115
115
  attributes = attributes.slice(*orig.class.accessible_attributes)
116
116
  elsif orig.class.respond_to? :protected_attributes
117
- orig.class.protected_attributes.each { |attr| dst.send :write_attribute, attr, orig[attr] }
117
+ orig.class.protected_attributes.each { |attr| dst.send :write_attribute, attr, orig[attr] if attr.present? }
118
118
  attributes = attributes.except(*orig.class.protected_attributes)
119
119
  end
120
120
  dst.attributes = attributes
@@ -8,25 +8,49 @@ module ActionDispatch
8
8
  :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post},
9
9
  :member => {:edit_associated => :get, :destroy_existing => :delete}
10
10
  }
11
+
11
12
  class Mapper
12
- module Base
13
- def as_routes(options = {:association => true})
14
- collection do
15
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| match(name, :via => type)}
13
+ module Resources
14
+ class ActiveScaffold < Resource
15
+ def default_actions
16
+ @default_actions ||= (ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].keys + ACTIVE_SCAFFOLD_CORE_ROUTING[:member].keys).uniq
16
17
  end
17
- member do
18
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| match(name, :via => type)}
19
- get 'list', :action => :index
18
+ end
19
+ class ActiveScaffoldAssociation < Resource
20
+ def default_actions
21
+ @default_actions ||= (ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].keys + ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].keys).uniq
22
+ end
23
+ end
24
+
25
+ def as_routes(opts = {:association => true})
26
+ resource_scope(:resource, ActiveScaffold.new(parent_resource.name, parent_resource.options)) do
27
+ collection do
28
+ ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each do |name, type|
29
+ match(name, :via => type) if parent_resource.actions.include? name
30
+ end
31
+ end
32
+ member do
33
+ ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each do |name, type|
34
+ match(name, :via => type) if parent_resource.actions.include? name
35
+ end
36
+ get 'list', :action => :index if parent_resource.actions.include? :index
37
+ end
20
38
  end
21
- as_association_routes if options[:association]
39
+ as_association_routes if opts[:association]
22
40
  end
23
41
 
24
42
  def as_association_routes
25
- collection do
26
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each {|name, type| send(type, name)}
27
- end
28
- member do
29
- ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)}
43
+ resource_scope(:resource, ActiveScaffoldAssociation.new(parent_resource.name, parent_resource.options)) do
44
+ collection do
45
+ ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each do |name, type|
46
+ match(name, :via => type) if parent_resource.actions.include? name
47
+ end
48
+ end
49
+ member do
50
+ ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
51
+ match(name, :via => type) if parent_resource.actions.include? name
52
+ end
53
+ end
30
54
  end
31
55
  end
32
56
 
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 8
5
+ PATCH = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class RoutingMapperTest < ActionController::TestCase
4
+ test 'rails routes' do
5
+ assert_routing 'addresses', :controller => 'addresses', :action => 'index'
6
+ assert_routing 'addresses/1', :controller => 'addresses', :action => 'show', :id => '1'
7
+ assert_routing 'addresses/1/edit', :controller => 'addresses', :action => 'edit', :id => '1'
8
+ assert_routing({:method => :put, :path => 'addresses/1'}, {:controller => 'addresses', :action => 'update', :id => '1'})
9
+ assert_routing({:method => :delete, :path => 'addresses/1'}, {:controller => 'addresses', :action => 'destroy', :id => '1'})
10
+ assert_routing({:method => :post, :path => 'addresses'}, {:controller => 'addresses', :action => 'create'})
11
+ end
12
+
13
+ test 'active scaffold routes' do
14
+ assert_routing 'addresses/show_search', :controller => 'addresses', :action => 'show_search'
15
+ assert_routing({:method => 'post', :path => 'addresses/render_field'}, :controller => 'addresses', :action => 'render_field')
16
+ assert_routing({:method => 'post', :path => 'addresses/2/render_field'}, :controller => 'addresses', :action => 'render_field', :id => '2')
17
+ assert_routing 'addresses/2/render_field', :controller => 'addresses', :action => 'render_field', :id => '2'
18
+ assert_routing 'addresses/edit_associated', :controller => 'addresses', :action => 'edit_associated'
19
+ assert_routing 'addresses/2/edit_associated', :controller => 'addresses', :action => 'edit_associated', :id => '2'
20
+ end
21
+ end
@@ -1,3 +1,6 @@
1
1
  RailsApp::Application.routes.draw do
2
+ resources :addresses do
3
+ as_routes
4
+ end
2
5
  match ':controller(/:action(/:id))', :via => :any
3
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.8
4
+ version: 3.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -364,6 +364,7 @@ files:
364
364
  - test/data_structures/validation_reflection_test.rb
365
365
  - test/data_structures/virtual_column_test.rb
366
366
  - test/extensions/active_record_test.rb
367
+ - test/extensions/routing_mapper_test.rb
367
368
  - test/helpers/form_column_helpers_test.rb
368
369
  - test/helpers/list_column_helpers_test.rb
369
370
  - test/helpers/pagination_helpers_test.rb
@@ -470,6 +471,7 @@ test_files:
470
471
  - test/data_structures/validation_reflection_test.rb
471
472
  - test/data_structures/virtual_column_test.rb
472
473
  - test/extensions/active_record_test.rb
474
+ - test/extensions/routing_mapper_test.rb
473
475
  - test/helpers/form_column_helpers_test.rb
474
476
  - test/helpers/list_column_helpers_test.rb
475
477
  - test/helpers/pagination_helpers_test.rb