qm-acts-as-generic-controller 0.1.10 → 0.1.11
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.
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gemspec.email = "marcin@saepia.net"
|
10
10
|
gemspec.homepage = "http://q.saepia.net"
|
11
11
|
gemspec.authors = ["Marcin Lewandowski"]
|
12
|
-
gemspec.version = "0.1.
|
12
|
+
gemspec.version = "0.1.11"
|
13
13
|
gemspec.files = Rake::FileList.new [ "MIT-LICENSE", "Rakefile", "lib/*", "app/views/generic_controller/*" ]
|
14
14
|
gemspec.add_dependency "qui-common-helpers", ">= 0.0.8"
|
15
15
|
gemspec.add_dependency "qui-index-table", ">= 0.0.8"
|
@@ -1,7 +1,9 @@
|
|
1
1
|
<%- records ||= instance_variable_get("@#{@controller.class.to_s.demodulize.gsub("Controller", "").tableize}") -%>
|
2
2
|
<%- class_name ||= @controller.class.to_s.demodulize.gsub("Controller", "").singularize.constantize -%>
|
3
3
|
|
4
|
-
<%-
|
4
|
+
<%- privileged_fields = class_name.generic_fields(:action => :index).collect{|field| field if not current_user.respond_to? "has_privileges?" or (class_name.generic_field_associations.has_key?(field[:name]) and current_user.has_privileges?(:class_name => class_name.generic_field_associations[field[:name]][:class_name])) or (current_user.has_privileges?(:class_name => class_name, :attribute => field[:name], :mode => :read)) } -%>
|
5
|
+
|
6
|
+
<%- headers = privileged_fields.collect{ |x| x[:options][:index_header] || ".#{x[:name]}".to_sym } -%>
|
5
7
|
|
6
8
|
<%- controller_name = "#{defined?(section) ? "#{section.to_s.camelize}::" : ""}#{class_name.to_s.pluralize}".tableize %>
|
7
9
|
|
@@ -23,17 +25,16 @@
|
|
23
25
|
<%- headers << :oneicon if has_edit %>
|
24
26
|
<%- headers << :oneicon if has_delete %>
|
25
27
|
|
28
|
+
|
26
29
|
<%- index_table records, :headers => headers, :class_name => class_name do |r| %>
|
27
|
-
<%-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
</td>
|
36
|
-
<%- end -%>
|
30
|
+
<%- privileged_fields.each do |field| -%>
|
31
|
+
<td>
|
32
|
+
<%- if field[:options].has_key? :renderer -%>
|
33
|
+
<%= send(field[:options][:renderer], { :record => r, :field => field, :action => :index }) %>
|
34
|
+
<%- else -%>
|
35
|
+
<%= generic_renderer(:index, { :record => r, :field => field }) %>
|
36
|
+
<%- end -%>
|
37
|
+
</td>
|
37
38
|
<%- end -%>
|
38
39
|
|
39
40
|
<%- if defined?(QM::ActsAsWorkflow) and class_name.is_workflow? -%>
|
@@ -15,17 +15,19 @@
|
|
15
15
|
|
16
16
|
<%- description = capture do -%>
|
17
17
|
<dl>
|
18
|
-
<%- klass.generic_fields(:action => :show).each do |field| -%>
|
19
|
-
<%-
|
18
|
+
<%- klass.generic_fields(:action => :show).collect{|field| field if not current_user.respond_to? "has_privileges?" or (current_user.respond_to? "has_privileges?" and current_user.has_privileges?(:class_name => klass, :attribute => field[:name])) }.compact.each do |field| -%>
|
19
|
+
<%- data = capture do -%>
|
20
|
+
<%- if field[:options].has_key? :renderer -%>
|
21
|
+
<%= send(field[:options][:renderer], { :record => record, :field => field, :action => :show }) %>
|
22
|
+
<%- else -%>
|
23
|
+
<%= generic_renderer(:show, { :record => record, :field => field }) %>
|
24
|
+
<%- end -%>
|
25
|
+
<%- end -%>
|
26
|
+
|
27
|
+
<%- unless data.strip.empty? -%>
|
20
28
|
<dt><%= h klass.human_attribute_name field[:name] %></dt>
|
21
29
|
|
22
|
-
<dd>
|
23
|
-
<%- if field[:options].has_key? :renderer -%>
|
24
|
-
<%= send(field[:options][:renderer], { :record => record, :field => field, :action => :show }) %>
|
25
|
-
<%- else -%>
|
26
|
-
<%= generic_renderer(:show, { :record => record, :field => field }) %>
|
27
|
-
<%- end -%>
|
28
|
-
</dd>
|
30
|
+
<dd><%= data %></dd>
|
29
31
|
<%- end -%>
|
30
32
|
<%- end -%>
|
31
33
|
</dl>
|
@@ -116,6 +116,9 @@ module QM
|
|
116
116
|
remove_unprivileged_keys_from_params
|
117
117
|
|
118
118
|
instance_variable_set(singular_variable, model.new(params[singular_variable(true)])) unless instance_variable_defined?(singular_variable)
|
119
|
+
|
120
|
+
save_creator
|
121
|
+
save_updator
|
119
122
|
|
120
123
|
respond_to do |format|
|
121
124
|
if instance_variable_get(singular_variable).save
|
@@ -186,6 +189,7 @@ module QM
|
|
186
189
|
remove_unprivileged_keys_from_params
|
187
190
|
|
188
191
|
instance_variable_get(singular_variable).update_attributes params[singular_variable(true)]
|
192
|
+
save_updator
|
189
193
|
|
190
194
|
respond_to do |format|
|
191
195
|
if instance_variable_get(singular_variable).save
|
@@ -230,6 +234,14 @@ module QM
|
|
230
234
|
end
|
231
235
|
|
232
236
|
protected
|
237
|
+
def save_creator
|
238
|
+
instance_variable_get(singular_variable).send("creator_#{current_user.class.to_s.tableize.singularize}_id=", current_user.id) if defined?(current_user) and instance_variable_get(singular_variable).respond_to? "creator_#{current_user.class.to_s.tableize.singularize}_id="
|
239
|
+
end
|
240
|
+
|
241
|
+
def save_updator
|
242
|
+
instance_variable_get(singular_variable).send("updator_#{current_user.class.to_s.tableize.singularize}_id=", current_user.id) if defined?(current_user) and instance_variable_get(singular_variable).respond_to? "updator_#{current_user.class.to_s.tableize.singularize}_id="
|
243
|
+
end
|
244
|
+
|
233
245
|
def model
|
234
246
|
self.class.to_s.demodulize.gsub("Controller", "").singularize.constantize
|
235
247
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qm-acts-as-generic-controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 11
|
10
|
+
version: 0.1.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marcin Lewandowski
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-18 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|