qm-acts-as-generic-controller 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -9,9 +9,9 @@ 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.1"
|
13
13
|
gemspec.files = Rake::FileList.new [ "MIT-LICENSE", "Rakefile", "lib/*", "app/views/generic_controller/*" ]
|
14
|
-
gemspec.add_dependency "qui-common-helpers", ">= 0.0.
|
14
|
+
gemspec.add_dependency "qui-common-helpers", ">= 0.0.8"
|
15
15
|
gemspec.add_dependency "qui-index-table", ">= 0.0.8"
|
16
16
|
gemspec.add_dependency "qui-tabs", ">= 0.0.3"
|
17
17
|
gemspec.add_dependency "qui-toolbar", ">= 0.0.4"
|
@@ -11,6 +11,7 @@
|
|
11
11
|
<%- end -%>
|
12
12
|
|
13
13
|
<%- if defined?(QUI::IndexTable) -%>
|
14
|
+
<%- class_name.generic_actions(:action => :index).size.times{ headers << :oneicon } -%>
|
14
15
|
|
15
16
|
<%- headers << :oneicon if has_edit %>
|
16
17
|
<%- headers << :oneicon if has_delete %>
|
@@ -34,12 +35,16 @@
|
|
34
35
|
</td>
|
35
36
|
<%- end -%>
|
36
37
|
|
38
|
+
<%- class_name.generic_actions(:action => :index).each do |action| -%>
|
39
|
+
<%= content_tag(:td, send(action[:options][:renderer], { :action => :index, :record => r, :action => action }), :class => "action #{action[:name]}") %>
|
40
|
+
<%- end -%>
|
41
|
+
|
37
42
|
<%- if has_edit -%>
|
38
|
-
<td><%= link_to_edit r %></td>
|
43
|
+
<td class="action edit"><%= link_to_edit r %></td>
|
39
44
|
<%- end -%>
|
40
45
|
|
41
46
|
<%- if has_delete -%>
|
42
|
-
<td><%= link_to_delete r %></td>
|
47
|
+
<td class="action delete"><%= link_to_delete r %></td>
|
43
48
|
<%- end -%>
|
44
49
|
|
45
50
|
|
@@ -35,7 +35,7 @@
|
|
35
35
|
<li>
|
36
36
|
<%= f.label field[:name] %>
|
37
37
|
|
38
|
-
<%- if
|
38
|
+
<%- if klass.is_enum?(field[:name]) -%>
|
39
39
|
<%= f.select field[:name], t("activerecord.enums.#{table_name}.#{field[:name]}").collect{|k,v| [v, k.to_s] }.sort{|x,y| x.last.to_i <=> y.last.to_i }, { :selected => params[table_name] ? params[table_name][field[:name]].to_s : f.object.send(field[:name]).to_s } %>
|
40
40
|
|
41
41
|
<%- elsif klass.generic_field_associations[field[:name]] -%>
|
@@ -64,9 +64,18 @@ module QM
|
|
64
64
|
end
|
65
65
|
|
66
66
|
|
67
|
+
|
68
|
+
def generic_actions(options = {})
|
69
|
+
@generic_actions ||= {}
|
70
|
+
if options.has_key? :action
|
71
|
+
@generic_actions[options[:action]] || []
|
72
|
+
else
|
73
|
+
@generic_actions || []
|
74
|
+
end
|
75
|
+
end
|
67
76
|
|
68
77
|
def generic_fields(options = {})
|
69
|
-
@generic_fields ||= {}
|
78
|
+
@generic_fields ||= {}
|
70
79
|
if options.has_key? :action
|
71
80
|
@generic_fields[options[:action]] || []
|
72
81
|
else
|
@@ -94,6 +103,24 @@ module QM
|
|
94
103
|
@generic_fields[actions.to_sym] << { :name => name.to_sym, :options => options }
|
95
104
|
end
|
96
105
|
end
|
106
|
+
|
107
|
+
def has_generic_action_for(actions, name, options = {})
|
108
|
+
options = options.symbolize_keys!
|
109
|
+
@generic_actions ||= {}
|
110
|
+
|
111
|
+
if actions.is_a? Array
|
112
|
+
actions.each do |action|
|
113
|
+
raise ArgumentError, "action must be one of :index, :show, :form" unless [ :index, :show, :form ].include? action.to_sym
|
114
|
+
@generic_actions[action.to_sym] ||= []
|
115
|
+
@generic_actions[action.to_sym] << { :name => name.to_sym, :options => options }
|
116
|
+
end
|
117
|
+
else
|
118
|
+
raise ArgumentError, "action must be one of :index, :show, :form" unless [ :index, :show, :form ].include? actions.to_sym
|
119
|
+
@generic_actions[actions.to_sym] ||= []
|
120
|
+
@generic_actions[actions.to_sym] << { :name => name.to_sym, :options => options }
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
97
124
|
|
98
125
|
def has_generic_form_fieldsets(*fieldsets)
|
99
126
|
@generic_form_fieldsets = fieldsets.flatten
|
@@ -13,6 +13,12 @@ module QM
|
|
13
13
|
elsif data.is_a?(Array) and data.first.is_a?(ActiveRecord::Base)
|
14
14
|
result = data.collect{ |x| link_to_object(x) }.sort_alphabetical.join(", ")
|
15
15
|
|
16
|
+
elsif options[:record].class.is_enum? options[:field][:name]
|
17
|
+
result = t("activerecord.enums.#{options[:record].class.table_name.singularize}.#{options[:field][:name]}.#{data}")
|
18
|
+
|
19
|
+
elsif options[:record].class.columns_hash[options[:field][:name].to_s].type == :boolean
|
20
|
+
result = data ? image_tag("tick.png", :alt => t(:"genericController.yesAsBooleanOption")) : ""
|
21
|
+
|
16
22
|
elsif defined?(RFC822) and data.is_a?(String) and data =~ RFC822::EMAIL_REGEXP_WHOLE
|
17
23
|
result = link_to data, "mailto:#{data}"
|
18
24
|
|
@@ -20,9 +26,6 @@ module QM
|
|
20
26
|
result = h data
|
21
27
|
end
|
22
28
|
|
23
|
-
|
24
|
-
puts options.inspect
|
25
|
-
|
26
29
|
result = link_to_object options[:record], result if options[:field][:options][:link_to] == :show
|
27
30
|
|
28
31
|
result
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
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-10-
|
18
|
+
date: 2010-10-20 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 15
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 0
|
33
|
-
-
|
34
|
-
version: 0.0.
|
33
|
+
- 8
|
34
|
+
version: 0.0.8
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|