qm-acts-as-generic-controller 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
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.0.7"
12
+ gemspec.version = "0.0.8"
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.6"
15
15
  gemspec.add_dependency "rfc822"
@@ -0,0 +1,31 @@
1
+ <%- records ||= instance_variable_get("@#{@controller.class.to_s.demodulize.gsub("Controller", "").tableize}") -%>
2
+ <%- class_name ||= @controller.class.to_s.demodulize.gsub("Controller", "").singularize.constantize -%>
3
+
4
+ <%- headers = class_name.generic_fields.collect{|x| x.is_a?(Hash) ? ".#{x.keys.first}".to_sym : ".#{x}".to_sym} -%>
5
+ <%- controller_name = "#{defined?(section) ? "#{section.to_s.camelize}::" : ""}#{class_name.to_s.pluralize}".tableize %>
6
+ <%- has_edit = ActionController::Routing::Routes.routes.collect{|x| x if x.matches_controller_and_action?(controller_name, "edit") }.compact.size > 0 %>
7
+ <%- has_delete = ActionController::Routing::Routes.routes.collect{|x| x if x.matches_controller_and_action?(controller_name, "destroy") }.compact.size > 0 %>
8
+
9
+
10
+ <%- if defined?(QUI::IndexTable) -%>
11
+
12
+ <%- headers << :oneicon if has_edit %>
13
+ <%- headers << :oneicon if has_delete %>
14
+
15
+ <%- index_table records, :headers => headers, :class_name => class_name do |r| %>
16
+ <%- class_name.generic_fields.each do |field| -%>
17
+ <td><%= render :partial => "generic_controller/data", :locals => { :record => r, :field => field } %></td>
18
+ <%- end -%>
19
+
20
+ <%- if has_edit -%>
21
+ <td><%= link_to_edit r %></td>
22
+ <%- end -%>
23
+
24
+ <%- if has_delete -%>
25
+ <td><%= link_to_delete r %></td>
26
+ <%- end -%>
27
+
28
+
29
+ <%- end -%>
30
+ <%- end -%>
31
+
@@ -74,7 +74,7 @@
74
74
  <%- klass.generic_field_associations[attribute_name][:class_name].all.each do |element| -%>
75
75
  <li>
76
76
  <%- if kind == :check -%>
77
- <%= check_box_tag "#{table_name}[#{attribute_name.to_s.singularize}_ids][]", element.id, (params[table_name] ? params[table_name]["#{attribute_name.to_s.singularize}_ids"].include?(element.id.to_s) : record.send("#{attribute_name.to_s.singularize}_ids").include?(element.id) ), :id => "#{table_name}_#{attribute_name}_#{element.id}" %>
77
+ <%= check_box_tag "#{table_name}[#{attribute_name.to_s.singularize}_ids][]", element.id, (params[table_name].present? and params[table_name]["#{attribute_name.to_s.singularize}_ids"].present? ? params[table_name]["#{attribute_name.to_s.singularize}_ids"].include?(element.id.to_s) : record.send("#{attribute_name.to_s.singularize}_ids").include?(element.id) ), :id => "#{table_name}_#{attribute_name}_#{element.id}" %>
78
78
 
79
79
  <%- elsif kind == :radio -%>
80
80
  <%= radio_button_tag "#{table_name}[#{klass.generic_field_associations[attribute_name][:foreign_key]}]", element.id, (params[table_name] ? params[table_name]["#{table_name}[#{klass.generic_field_associations[attribute_name][:foreign_key]}]"] == element.id.to_s : record.send(klass.generic_field_associations[attribute_name][:foreign_key]) == element.id), :id => "#{table_name}_#{attribute_name}_#{element.id}" %>
@@ -1,30 +1,13 @@
1
1
  <%- if defined?(QUI::Toolbar) -%>
2
2
  <%- toolbar do |t| -%>
3
- <%= t.create %>
4
- <%- end -%>
5
- <%- end -%>
6
-
7
- <%- if defined?(QUI::IndexTable) -%>
8
- <%- klass = @controller.class.to_s.demodulize.gsub("Controller", "").singularize.constantize -%>
9
- <%- headers = klass.generic_fields.collect{|x| x.is_a?(Hash) ? ".#{x.keys.first}".to_sym : ".#{x}".to_sym} -%>
10
- <%- has_edit = ActionController::Routing::Routes.routes.collect{|x| x if x.matches_controller_and_action?(@controller.class.to_s.gsub("Controller", "").tableize, "edit") }.compact.size > 0 %>
11
- <%- has_destroy = ActionController::Routing::Routes.routes.collect{|x| x if x.matches_controller_and_action?(@controller.class.to_s.gsub("Controller", "").tableize, "destroy") }.compact.size > 0 %>
12
-
13
- <%- headers << :oneicon if has_edit %>
14
- <%- headers << :oneicon if has_destroy %>
15
-
16
- <%- index_table instance_variable_get("@#{@controller.class.to_s.demodulize.gsub("Controller", "").tableize}"), :headers => headers, :class_name => klass do |r| %>
17
- <%- klass.generic_fields.each do |field| -%>
18
- <%- if field.is_a? Hash -%>
19
- <%- attribute_name = field.keys.first.to_sym -%>
20
- <%- else -%>
21
- <%- attribute_name = field.to_sym -%>
3
+ <%- begin -%>
4
+ <%= t.create %>
5
+ <%- rescue -%>
6
+ <%- capture do -%>
7
+ <%- logger.debug "Toolbar: Cannot generate Create button: #{$!}" -%>
22
8
  <%- end -%>
23
-
24
- <td><%= render :partial => "generic_controller/data", :locals => { :record => r, :field => field } %></td>
25
9
  <%- end -%>
26
-
27
- <td><%= link_to_edit r if has_edit %></td>
28
- <td><%= link_to_delete r if has_destroy %></td>
29
10
  <%- end -%>
30
11
  <%- end -%>
12
+
13
+ <%= render :partial => "generic_controller/index_table" %>
@@ -10,16 +10,34 @@
10
10
  <%- klass = @controller.class.to_s.demodulize.gsub("Controller", "").singularize.constantize -%>
11
11
  <%- table_name = "#{@controller.class.to_s.demodulize.gsub("Controller", "").tableize.singularize}" -%>
12
12
  <%- record = instance_variable_get("@#{@controller.class.to_s.demodulize.gsub("Controller", "").tableize.singularize}") -%>
13
- <dl>
14
- <%- klass.generic_fields.each do |field| -%>
15
- <%- if field.is_a? Hash -%>
16
- <%- attribute_name = field.keys.first.to_sym -%>
17
- <%- else -%>
18
- <%- attribute_name = field.to_sym -%>
19
- <%- end -%>
20
13
 
21
- <dt><%= h klass.human_attribute_name attribute_name %></dt>
14
+ <%- section_prefix = "#{section}." if defined?(section) -%>
15
+
16
+ <%- description = capture do -%>
17
+ <dl>
18
+ <%- klass.generic_fields.each do |field| -%>
19
+ <%- if field.is_a? Hash -%>
20
+ <%- attribute_name = field.keys.first.to_sym -%>
21
+ <%- else -%>
22
+ <%- attribute_name = field.to_sym -%>
23
+ <%- end -%>
24
+
25
+ <dt><%= h klass.human_attribute_name attribute_name %></dt>
26
+
27
+ <dd><%= render :partial => "generic_controller/data", :locals => { :record => record, :field => field } %></dd>
28
+ <%- end -%>
29
+ </dl>
30
+ <%- end -%>
22
31
 
23
- <dd><%= render :partial => "generic_controller/data", :locals => { :record => record, :field => field } %></dd>
32
+ <%- tab_contents = {} -%>
33
+ <%- record.class.generic_field_associations.each do |k,v| -%>
34
+ <%- if (v[:kind] == :has_many or v[:kind] == :has_and_belongs_to_many) and not v[:through] -%>
35
+ <%- tab_contents[k] = capture do -%>
36
+ <%= render :partial => "generic_controller/index_table", :locals => { :records => record.send(k), :class_name => v[:class_name] } %>
37
+ <%- end -%>
24
38
  <%- end -%>
25
- </dl>
39
+ <%- end -%>
40
+
41
+ <%= tabs :tabs => [ { :header => { :text => :"#{section_prefix}tabs.common.description" }, :body => { :text => description } } ] + record.class.generic_field_associations.collect{|k,v| { :header => { :text => t(:"#{section_prefix}tabs.#{table_name}.#{k}") + " (#{record.send(k).count})" }, :body => { :text => tab_contents[k] } } if (v[:kind] == :has_many or v[:kind] == :has_and_belongs_to_many) and v[:through] == false and record.send(k).count > 0 }.compact -%>
42
+
43
+
@@ -13,14 +13,14 @@ module QM
13
13
 
14
14
  def has_many(association_id, options = {}, &extension)
15
15
  @generic_field_associations ||= {}
16
- @generic_field_associations[association_id.to_sym] = { :kind => :has_many, :class_name => ( options[:class_name] ? options[:class_name].constantize : association_id.to_s.classify.constantize ), :readonly => options[:readonly] || false }
16
+ @generic_field_associations[association_id.to_sym] = { :kind => :has_many, :class_name => ( options[:class_name] ? options[:class_name].constantize : association_id.to_s.classify.constantize ), :readonly => options[:readonly] || false, :through => options[:through].present? }
17
17
 
18
18
  super association_id, options, &extension
19
19
  end
20
20
 
21
21
  def has_and_belongs_to_many(association_id, options = {}, &extension)
22
22
  @generic_field_associations ||= {}
23
- @generic_field_associations[association_id.to_sym] = { :kind => :has_and_belongs_to_many, :class_name => ( options[:class_name] ? options[:class_name].constantize : association_id.to_s.classify.constantize ), :readonly => options[:readonly] || false }
23
+ @generic_field_associations[association_id.to_sym] = { :kind => :has_and_belongs_to_many, :class_name => ( options[:class_name] ? options[:class_name].constantize : association_id.to_s.classify.constantize ), :readonly => options[:readonly] || false, :through => options[:through].present? }
24
24
 
25
25
  super association_id, options, &extension
26
26
  end
@@ -36,7 +36,7 @@ module QM
36
36
 
37
37
 
38
38
  def generic_fields
39
- @generic_fields
39
+ @generic_fields || []
40
40
  end
41
41
 
42
42
  def generic_form_fieldsets
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: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcin Lewandowski
@@ -74,6 +74,7 @@ files:
74
74
  - MIT-LICENSE
75
75
  - Rakefile
76
76
  - app/views/generic_controller/_data.erb
77
+ - app/views/generic_controller/_index_table.erb
77
78
  - app/views/generic_controller/_multiple_select.erb
78
79
  - app/views/generic_controller/form.erb
79
80
  - app/views/generic_controller/index.erb