active_scaffold 3.4.8 → 3.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -1
- data/app/assets/javascripts/jquery/active_scaffold.js +8 -7
- data/app/views/active_scaffold_overrides/_list_record.html.erb +2 -1
- data/app/views/active_scaffold_overrides/destroy.js.erb +6 -2
- data/app/views/active_scaffold_overrides/on_create.js.erb +1 -1
- data/app/views/active_scaffold_overrides/on_update.js.erb +1 -1
- data/lib/active_scaffold/actions/core.rb +3 -3
- data/lib/active_scaffold/extensions/routing_mapper.rb +37 -13
- data/lib/active_scaffold/version.rb +1 -1
- data/test/extensions/routing_mapper_test.rb +21 -0
- data/test/mock_app/config/routes.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c83a7d7ce3f57146d10cbf6134cc41c46f4753e3
|
4
|
+
data.tar.gz: 4e19dd8122bde0ded7a956146709fa981d05a9bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 397d444554b333a865f9c9302655a3d5519c48dcc1dd768be0317a66e94c29d4b70f087809ac4cca049a2ed295b4b53971811a1fcbd7c3e42a9536bea2b41de2
|
7
|
+
data.tar.gz: 2e5a2a8706e97af1a82f35335e55a4abc6e97c9156e3d23ef2ad093ca868c473f9f8b425ce926600a4d013b9b05d586b31e87e22b5d8b97ab726d4dceb95aaff
|
data/CHANGELOG
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
= 3.4.
|
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')
|
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
|
-
|
604
|
-
jQuery(form_selector + ":input
|
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="<%=
|
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
|
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
|
-
|
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
|
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
|
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
|
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)
|
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
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
39
|
+
as_association_routes if opts[:association]
|
22
40
|
end
|
23
41
|
|
24
42
|
def as_association_routes
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
|
@@ -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
|
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.
|
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-
|
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
|