active_scaffold 3.0.21 → 3.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ <%
2
+ @record = parent_record
3
+
4
+ show_add_existing = column_show_add_existing(column)
5
+ show_add_new = column_show_add_new(column, associated, @record)
6
+
7
+ return unless show_add_new or show_add_existing
8
+
9
+ edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing
10
+ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new
11
+
12
+ -%>
13
+ <div class="footer-wrapper">
14
+ <div class="footer">
15
+ <% if show_add_new -%>
16
+ <% if column.plural_association?
17
+ add_label = as_(:create_another, :model => column.association.klass.model_name.human)
18
+ add_class = 'as_create_another'
19
+ else
20
+ add_label = as_(:replace_with_new)
21
+ add_class = 'as_replace_with_new'
22
+ end
23
+ create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %>
24
+ <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :class => add_class, :style=> "display: none;"}) %>
25
+ <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %>
26
+ <% end -%>
27
+
28
+ <%= '|' if show_add_new and show_add_existing %>
29
+
30
+ <% if show_add_existing -%>
31
+ <% select_options = options_for_select(options_for_association(column.association))
32
+ add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %>
33
+ <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %>
34
+ <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;"}) %>
35
+ <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %>
36
+ <% end -%>
37
+ </div>
38
+ </div>
@@ -1,4 +1,7 @@
1
1
  column = active_scaffold_config.columns[render_field.to_sym]
2
+ @rendered ||= Set.new
3
+ return if @rendered.include? column.name
4
+ @rendered << column.name
2
5
  if column_renders_as(column) == :subform
3
6
  options = {:is_subform => true, :field_class => "#{column.name}-sub-form"}
4
7
  else
@@ -29,8 +29,8 @@ module ActiveScaffold::Actions
29
29
  end
30
30
 
31
31
  def render_field_for_update_columns
32
- @record = new_model
33
32
  column = active_scaffold_config.columns[params[:column]]
33
+ @record = params[:id] && column.send_form_on_update_column ? find_if_allowed(params[:id], :update) : new_model
34
34
  unless column.nil?
35
35
  if column.send_form_on_update_column
36
36
  hash = if params[:scope]
@@ -40,7 +40,7 @@ module ActiveScaffold::Actions
40
40
  else
41
41
  params[:record]
42
42
  end
43
- @record = update_record_from_params(@record, active_scaffold_config.update.columns, hash)
43
+ @record = update_record_from_params(@record, active_scaffold_config.send(params[:id] ? :update : :create).columns, hash)
44
44
  else
45
45
  value = column_value_from_param_value(@record, column, params[:value])
46
46
  @record.send "#{column.name}=", value
@@ -0,0 +1,191 @@
1
+ module ActiveScaffold::Actions
2
+ module Core
3
+ def self.included(base)
4
+ base.class_eval do
5
+ after_filter :clear_flashes
6
+ end
7
+ base.helper_method :nested?
8
+ base.helper_method :beginning_of_chain
9
+ base.helper_method :new_model
10
+ end
11
+ def render_field
12
+ if params[:in_place_editing]
13
+ render_field_for_inplace_editing
14
+ else
15
+ render_field_for_update_columns
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ def nested?
22
+ false
23
+ end
24
+
25
+ def render_field_for_inplace_editing
26
+ register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested?
27
+ @record = find_if_allowed(params[:id], :update)
28
+ render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>"
29
+ end
30
+
31
+ def render_field_for_update_columns
32
+ @record = new_model
33
+ column = active_scaffold_config.columns[params[:column]]
34
+ unless column.nil?
35
+ if column.send_form_on_update_column
36
+ hash = if params[:scope]
37
+ hash = params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index|
38
+ hash[index]
39
+ end
40
+ else
41
+ params[:record]
42
+ end
43
+ @record = update_record_from_params(@record, active_scaffold_config.send(params[:id] ? :update : :create).columns, hash)
44
+ else
45
+ value = column_value_from_param_value(@record, column, params[:value])
46
+ @record.send "#{column.name}=", value
47
+ end
48
+ after_render_field(@record, column)
49
+ source_id = params.delete(:source_id)
50
+ render :locals => {:source_id => source_id, :columns => column.update_columns, :scope => params[:scope]}
51
+ end
52
+ end
53
+
54
+ # override this method if you want to do something after render_field
55
+ def after_render_field(record, column); end
56
+
57
+ def authorized_for?(options = {})
58
+ active_scaffold_config.model.authorized_for?(options)
59
+ end
60
+
61
+ def clear_flashes
62
+ if request.xhr?
63
+ flash.keys.each do |flash_key|
64
+ flash[flash_key] = nil
65
+ end
66
+ end
67
+ end
68
+
69
+ def default_formats
70
+ [:html, :js, :json, :xml, :yaml]
71
+ end
72
+ # Returns true if the client accepts one of the MIME types passed to it
73
+ # ex: accepts? :html, :xml
74
+ def accepts?(*types)
75
+ for priority in request.accepts.compact
76
+ if priority == Mime::ALL
77
+ # Because IE always sends */* in the accepts header and we assume
78
+ # that if you really wanted XML or something else you would say so
79
+ # explicitly, we will assume */* to only ask for :html
80
+ return types.include?(:html)
81
+ elsif types.include?(priority.to_sym)
82
+ return true
83
+ end
84
+ end
85
+ false
86
+ end
87
+
88
+ def response_status
89
+ if successful?
90
+ action_name == 'create' ? 201 : 200
91
+ else
92
+ 422
93
+ end
94
+ end
95
+
96
+ # API response object that will be converted to XML/YAML/JSON using to_xxx
97
+ def response_object
98
+ @response_object = successful? ? (@record || @records) : @record.errors
99
+ end
100
+
101
+ # Success is the existence of certain variables and the absence of errors (when applicable).
102
+ # Success can also be defined.
103
+ def successful?
104
+ if @successful.nil?
105
+ @records or (@record and @record.errors.count == 0 and @record.no_errors_in_associated?)
106
+ else
107
+ @successful
108
+ end
109
+ end
110
+
111
+ def successful=(val)
112
+ @successful = (val) ? true : false
113
+ end
114
+
115
+ # Redirect to the main page (override if the ActiveScaffold is used as a component on another controllers page) for Javascript degradation
116
+ def return_to_main
117
+ redirect_to main_path_to_return
118
+ end
119
+
120
+ # Override this method on your controller to define conditions to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :conditions clause of ActiveRecord::Base's find.
121
+ def conditions_for_collection
122
+ end
123
+
124
+ # Override this method on your controller to define joins to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :joins clause of ActiveRecord::Base's find.
125
+ def joins_for_collection
126
+ end
127
+
128
+ # Override this method on your controller to provide custom finder options to the find() call. The return of this method should be a hash.
129
+ def custom_finder_options
130
+ {}
131
+ end
132
+
133
+ #Overide this method on your controller to provide model with named scopes
134
+ def beginning_of_chain
135
+ active_scaffold_config.model
136
+ end
137
+
138
+ # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5".
139
+ def conditions_from_params
140
+ conditions = nil
141
+ params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value|
142
+ next unless active_scaffold_config.model.column_names.include?(key)
143
+ if value.is_a?(Array)
144
+ conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} in (?)", value])
145
+ else
146
+ conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} = ?", value])
147
+ end
148
+ end
149
+ conditions
150
+ end
151
+
152
+ def new_model
153
+ model = beginning_of_chain
154
+ if model.columns_hash[model.inheritance_column]
155
+ build_options = {model.inheritance_column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection?
156
+ params = self.params # in new action inheritance_column must be in params
157
+ params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key
158
+ model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column]
159
+ end
160
+ model.respond_to?(:build) ? model.build(build_options || {}) : model.new
161
+ end
162
+
163
+ private
164
+ def respond_to_action(action)
165
+ respond_to do |type|
166
+ action_formats.each do |format|
167
+ type.send(format){ send("#{action}_respond_to_#{format}") }
168
+ end
169
+ end
170
+ end
171
+
172
+ def action_formats
173
+ @action_formats ||= if respond_to? "#{action_name}_formats", true
174
+ send("#{action_name}_formats")
175
+ else
176
+ (default_formats + active_scaffold_config.formats).uniq
177
+ end
178
+ end
179
+
180
+ def response_code_for_rescue(exception)
181
+ case exception
182
+ when ActiveScaffold::RecordNotAllowed
183
+ "403 Record Not Allowed"
184
+ when ActiveScaffold::ActionNotAllowed
185
+ "403 Action Not Allowed"
186
+ else
187
+ super
188
+ end
189
+ end
190
+ end
191
+ end
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- PATCH = 21
5
+ PATCH = 22
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 43
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 21
10
- version: 3.0.21
9
+ - 22
10
+ version: 3.0.22
11
11
  platform: ruby
12
12
  authors:
13
13
  - Many, see README
@@ -15,13 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-29 00:00:00 +02:00
18
+ date: 2011-08-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: shoulda
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ">="
@@ -30,12 +28,12 @@ dependencies:
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
31
+ requirement: *id001
32
+ prerelease: false
33
33
  type: :development
34
- version_requirements: *id001
34
+ name: shoulda
35
35
  - !ruby/object:Gem::Dependency
36
- name: bundler
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
37
  none: false
40
38
  requirements:
41
39
  - - ~>
@@ -46,12 +44,12 @@ dependencies:
46
44
  - 0
47
45
  - 0
48
46
  version: 1.0.0
47
+ requirement: *id002
48
+ prerelease: false
49
49
  type: :development
50
- version_requirements: *id002
50
+ name: bundler
51
51
  - !ruby/object:Gem::Dependency
52
- name: rcov
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
53
  none: false
56
54
  requirements:
57
55
  - - ">="
@@ -60,12 +58,12 @@ dependencies:
60
58
  segments:
61
59
  - 0
62
60
  version: "0"
61
+ requirement: *id003
62
+ prerelease: false
63
63
  type: :development
64
- version_requirements: *id003
64
+ name: rcov
65
65
  - !ruby/object:Gem::Dependency
66
- name: render_component_vho
67
- prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
69
67
  none: false
70
68
  requirements:
71
69
  - - ">="
@@ -74,12 +72,12 @@ dependencies:
74
72
  segments:
75
73
  - 0
76
74
  version: "0"
75
+ requirement: *id004
76
+ prerelease: false
77
77
  type: :runtime
78
- version_requirements: *id004
78
+ name: render_component_vho
79
79
  - !ruby/object:Gem::Dependency
80
- name: verification
81
- prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
83
81
  none: false
84
82
  requirements:
85
83
  - - ">="
@@ -88,12 +86,12 @@ dependencies:
88
86
  segments:
89
87
  - 0
90
88
  version: "0"
89
+ requirement: *id005
90
+ prerelease: false
91
91
  type: :runtime
92
- version_requirements: *id005
92
+ name: verification
93
93
  - !ruby/object:Gem::Dependency
94
- name: rails
95
- prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
94
+ version_requirements: &id006 !ruby/object:Gem::Requirement
97
95
  none: false
98
96
  requirements:
99
97
  - - ~>
@@ -104,8 +102,10 @@ dependencies:
104
102
  - 0
105
103
  - 0
106
104
  version: 3.0.0
105
+ requirement: *id006
106
+ prerelease: false
107
107
  type: :runtime
108
- version_requirements: *id006
108
+ name: rails
109
109
  description: Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.
110
110
  email: activescaffold@googlegroups.com
111
111
  executables: []
@@ -195,6 +195,7 @@ files:
195
195
  - frontends/default/views/_search_attribute.html.erb
196
196
  - frontends/default/views/action_confirmation.html.erb
197
197
  - frontends/default/views/_base_form.html.erb~
198
+ - frontends/default/views/_form_association_footer.html.erb~
198
199
  - lib/active_scaffold.rb
199
200
  - lib/active_scaffold_env.rb
200
201
  - lib/active_scaffold/actions/common_search.rb
@@ -209,6 +210,7 @@ files:
209
210
  - lib/active_scaffold/actions/show.rb
210
211
  - lib/active_scaffold/actions/subform.rb
211
212
  - lib/active_scaffold/actions/update.rb
213
+ - lib/active_scaffold/actions/core.rb~
212
214
  - lib/active_scaffold/attribute_params.rb
213
215
  - lib/active_scaffold/config/base.rb
214
216
  - lib/active_scaffold/config/core.rb