qm-acts-as-generic-controller 0.1.17 → 0.1.18

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
@@ -10,7 +10,7 @@ begin
10
10
  gemspec.email = "marcin@saepia.net"
11
11
  gemspec.homepage = "http://q.saepia.net"
12
12
  gemspec.authors = ["Marcin Lewandowski"]
13
- gemspec.version = "0.1.17"
13
+ gemspec.version = "0.1.18"
14
14
  gemspec.files = Rake::FileList.new [ "MIT-LICENSE", "Rakefile", "lib/*", "app/views/generic_controller/*" ]
15
15
  gemspec.add_dependency "qui-common-helpers", ">= 0.0.8"
16
16
  gemspec.add_dependency "qui-index-table", ">= 0.0.8"
@@ -23,6 +23,10 @@
23
23
  <%- end -%>
24
24
 
25
25
 
26
+ <%- tab_contents = {} -%>
27
+ <%- tab_headers = {} -%>
28
+ <%- tabs_definition = [] -%>
29
+
26
30
 
27
31
  <%- description = capture do -%>
28
32
  <dl>
@@ -44,8 +48,18 @@
44
48
  </dl>
45
49
  <%- end -%>
46
50
 
47
- <%- tab_contents = {} -%>
48
- <%- tab_headers = {} -%>
51
+ <%- begin -%>
52
+ <%- summary = capture do -%>
53
+ <%= render :partial => (defined?(section) ? "#{section}/" : "") + "#{klass.table_name}/generic/summary", :locals => { :record => record, :klass => klass } %>
54
+ <%- end -%>
55
+ <%- tabs_definition << { :header => { :text => :"#{section_prefix}tabs.common.summary" }, :body => { :text => summary } } -%>
56
+
57
+ <%- rescue ActionView::MissingTemplate -%>
58
+ <%- end -%>
59
+
60
+ <%- tabs_definition << { :header => { :text => :"#{section_prefix}tabs.common.description" }, :body => { :text => description } } -%>
61
+
62
+
49
63
  <%- record.class.generic_field_associations.each do |k,v| -%>
50
64
  <%- if current_user.respond_to? "has_privileges?" -%>
51
65
  <%- has_privileges = current_user.has_privileges?(:class_name => v[:class_name], :generic_action => :index_any) || current_user.has_privileges?(:class_name => v[:class_name], :generic_action => :index_created)-%>
@@ -54,22 +68,34 @@
54
68
  <%- has_privileges = true -%>
55
69
  <%- has_privileges_to_generic_create = true -%>
56
70
  <%- end -%>
57
-
71
+
58
72
  <%- if has_privileges and (v[:kind] == :has_many or v[:kind] == :has_and_belongs_to_many) and (v[:generic_create] or not v[:through]) -%>
59
73
  <%- tab_contents[k] = capture do -%>
60
- <%- if v[:generic_create] and has_privileges_to_generic_create -%>
61
- <%- association_attribute = "#{v[:class_name].table_name.singularize}[#{table_name}_id]" -%>
62
- <%= link_to t(:"toolbar.create"), polymorphic_path([ "new", section, v[:class_name].table_name.singularize ], { association_attribute => record.id, :association_attribute => association_attribute }), :class => "create" %>
63
-
74
+ <%- begin -%>
75
+ <%= render :partial => (defined?(section) ? "#{section}/" : "") + "#{klass.table_name}/generic/associations/#{k.to_s}", :locals => { :records => record.send(k).limit_with_security_scheme(:user => current_user), :class_name => v[:class_name] } %>
76
+ <%- tab_headers[k] = t(:"#{section_prefix}tabs.#{table_name}.#{k}") %>
77
+
78
+ <%- rescue ActionView::MissingTemplate -%>
79
+ <%- if v[:generic_create] and has_privileges_to_generic_create -%>
80
+ <%- association_attribute = "#{v[:class_name].table_name.singularize}[#{table_name}_id]" -%>
81
+ <%= link_to t(:"toolbar.create"), polymorphic_path([ "new", section, v[:class_name].table_name.singularize ], { association_attribute => record.id, :association_attribute => association_attribute }), :class => "create" %>
82
+ <%- end -%>
83
+
84
+ <%= render :partial => "generic_controller/index_table", :locals => { :records => record.send(k).limit_with_security_scheme(:user => current_user), :class_name => v[:class_name] } %>
85
+ <%- tab_headers[k] = t(:"#{section_prefix}tabs.#{table_name}.#{k}") + " (#{record.send(k).limit_with_security_scheme(:user => current_user).size})" %>
64
86
  <%- end -%>
65
87
 
66
- <%- tab_headers[k] = t(:"#{section_prefix}tabs.#{table_name}.#{k}") + " (#{record.send(k).limit_with_security_scheme(:user => current_user).size})" %>
67
- <%= render :partial => "generic_controller/index_table", :locals => { :records => record.send(k).limit_with_security_scheme(:user => current_user), :class_name => v[:class_name] } %>
68
88
 
69
89
  <%- end -%>
70
90
  <%- end -%>
71
91
  <%- end -%>
72
92
 
73
- <%= tabs :tabs => [ { :header => { :text => :"#{section_prefix}tabs.common.description" }, :body => { :text => description } } ] + record.class.generic_field_associations.collect{|k,v| { :header => { :text => tab_headers[k] }, :body => { :text => tab_contents[k] } } if tab_contents.has_key?(k) and (v[:kind] == :has_many or v[:kind] == :has_and_belongs_to_many) and v[:through] == false and (record.send(k).count > 0 or v[:generic_create]) }.compact -%>
93
+ <%= tabs :tabs => tabs_definition +
94
+
95
+
96
+
97
+ record.class.generic_field_associations.collect{|k,v|
98
+ { :header => { :text => tab_headers[k] },
99
+ :body => { :text => tab_contents[k] } } if tab_contents.has_key?(k) and (v[:kind] == :has_many or v[:kind] == :has_and_belongs_to_many) and v[:through] == false and (record.send(k).count > 0 or v[:generic_create]) }.compact -%>
74
100
 
75
101
 
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: 57
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 17
10
- version: 0.1.17
9
+ - 18
10
+ version: 0.1.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcin Lewandowski