qm-acts-as-generic-controller 0.0.9 → 0.0.10
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.0.
|
12
|
+
gemspec.version = "0.0.10"
|
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"
|
@@ -1,13 +1,36 @@
|
|
1
|
-
<%-
|
2
|
-
|
1
|
+
<%- @mutliple_select_count ||= 0 -%>
|
2
|
+
|
3
|
+
<%- if defined?(field) and defined?(record) -%>
|
4
|
+
<%- if field.is_a? Hash -%>
|
5
|
+
<%- attribute_name = field.keys.first.to_sym -%>
|
6
|
+
<%- else -%>
|
7
|
+
<%- attribute_name = field.to_sym -%>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<%- klass = record.class -%>
|
11
|
+
<%- table_name = klass.to_s.tableize.singularize -%>
|
12
|
+
|
13
|
+
<%- if kind == :check -%>
|
14
|
+
<%- field_name = "#{table_name}[#{attribute_name.to_s.singularize}_ids][]" -%>
|
15
|
+
<%- allow_nil = false -%>
|
16
|
+
|
17
|
+
<%- elsif kind == :radio -%>
|
18
|
+
<%- field_name = "#{table_name}[#{klass.generic_field_associations[attribute_name][:foreign_key]}]" -%>
|
19
|
+
<%- allow_nil ||= record.column_for_attribute(klass.generic_field_associations[attribute_name][:foreign_key]).null -%>
|
20
|
+
<%- end -%>
|
21
|
+
|
22
|
+
<%- collection = klass.generic_field_associations[attribute_name][:class_name].all -%>
|
23
|
+
|
24
|
+
|
25
|
+
<%- elsif defined?(collection) and defined?(attribute_name) -%>
|
26
|
+
<%- allow_nil ||= false -%>
|
27
|
+
<%- field_name = attribute_name -%>
|
28
|
+
|
3
29
|
<%- else -%>
|
4
|
-
<%- attribute_name
|
30
|
+
<%- raise ArgumentError, "You must pass some variables as locals to generic_controller/multiple_select partial. Possibilities are: 'field' and 'record' for automatic associations, or 'collection' and 'attribute_name' just for displaying a set." -%>
|
5
31
|
<%- end -%>
|
6
32
|
|
7
|
-
<%-
|
8
|
-
<%- table_name = klass.to_s.tableize.singularize -%>
|
9
|
-
|
10
|
-
<%- content_tag(:div, :class => "multiple_select_select", :id => "multiple_select_select_for_#{attribute_name}") do -%>
|
33
|
+
<%- content_tag(:div, :class => "multiple_select", :id => "multiple_select_for_#{attribute_name}") do -%>
|
11
34
|
<%- content_tag(:div, :class => "filter") do -%>
|
12
35
|
<%= text_field_tag "multiple_select_filter_for_#{attribute_name}", "" %>
|
13
36
|
<%- javascript_tag do -%>
|
@@ -23,7 +46,7 @@
|
|
23
46
|
|
24
47
|
Event.observe(window, 'load', function() {
|
25
48
|
$("multiple_select_filter_for_<%= attribute_name %>").value = "";
|
26
|
-
$("
|
49
|
+
$("multiple_select_for_<%= attribute_name %>").select("input").each(function(el) {
|
27
50
|
if(el.checked)
|
28
51
|
$(el).up().addClassName('selected');
|
29
52
|
else
|
@@ -35,7 +58,7 @@
|
|
35
58
|
<%- if kind == :check -%>
|
36
59
|
<%- javascript_tag do -%>
|
37
60
|
Event.observe(window, 'load', function() {
|
38
|
-
$("
|
61
|
+
$("multiple_select_for_<%= attribute_name %>").select("input").each(function(el) {
|
39
62
|
el.onchange = function() {
|
40
63
|
if(this.checked)
|
41
64
|
$(this).up().addClassName('selected');
|
@@ -49,7 +72,7 @@
|
|
49
72
|
<%- elsif kind == :radio -%>
|
50
73
|
<%- javascript_tag do -%>
|
51
74
|
Event.observe(window, 'load', function() {
|
52
|
-
$("
|
75
|
+
$("multiple_select_for_<%= attribute_name %>").select("input").each(function(el) {
|
53
76
|
el.onchange = function() {
|
54
77
|
if(this.checked) {
|
55
78
|
$(this).up(1).select("li").each(function(el) { el.removeClassName('selected') });
|
@@ -64,24 +87,38 @@
|
|
64
87
|
<%- end -%>
|
65
88
|
|
66
89
|
<ul>
|
67
|
-
<%- if kind == :radio and
|
90
|
+
<%- if kind == :radio and allow_nil -%>
|
68
91
|
<li class="null">
|
69
|
-
<%= radio_button_tag
|
92
|
+
<%= radio_button_tag field_name, "", record.send(klass.generic_field_associations[attribute_name][:foreign_key]).nil?, :id => "#{table_name}_#{attribute_name}_null" %>
|
70
93
|
<%= label_tag "#{table_name}_#{attribute_name}_null", t(:"genericController.multipleSelectNull") %>
|
71
94
|
</li>
|
72
95
|
<%- end -%>
|
73
96
|
|
74
|
-
<%-
|
97
|
+
<%- collection.each do |element| -%>
|
75
98
|
<li>
|
76
99
|
<%- if kind == :check -%>
|
77
|
-
|
100
|
+
<%- if defined?(record) -%>
|
101
|
+
<%- selected = (params[table_name] && params[table_name]["#{attribute_name.to_s.singularize}_ids"] ? 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) ) -%>
|
102
|
+
<%- else -%>
|
103
|
+
<%- selected = params[table_name] && params[table_name].include?(element.id.to_s) -%>
|
104
|
+
<%- end -%>
|
105
|
+
|
106
|
+
<%= check_box_tag field_name, element.id, selected, :id => "ms#{@mutliple_select_count}_#{table_name}_#{attribute_name}_#{element.id}" %>
|
78
107
|
|
79
108
|
<%- elsif kind == :radio -%>
|
80
|
-
|
109
|
+
<%- if defined?(record) -%>
|
110
|
+
<%- selected = (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) -%>
|
111
|
+
<%- else -%>
|
112
|
+
<%- selected = params[table_name] && params[table_name] == element.id.to_s -%>
|
113
|
+
<%- end -%>
|
114
|
+
|
115
|
+
<%= radio_button_tag field_name, element.id, selected, :id => "ms#{@mutliple_select_count}_#{table_name}_#{attribute_name}_#{element.id}" %>
|
81
116
|
<%- end -%>
|
82
|
-
|
117
|
+
|
118
|
+
<%= label_tag "ms#{@mutliple_select_count}_#{table_name}_#{attribute_name}_#{element.id}", element.link_default_description %>
|
83
119
|
</li>
|
84
120
|
<%- end -%>
|
85
121
|
</ul>
|
86
122
|
<%- end -%>
|
87
123
|
|
124
|
+
<%- @mutliple_select_count += 1 -%>
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'qm-acts-as-generic-controller-controller.rb'
|
2
2
|
require 'qm-acts-as-generic-controller-model.rb'
|
3
|
+
require 'qm-acts-as-generic-controller-view.rb'
|
3
4
|
|
4
5
|
ActiveRecord::Base.send :include, QM::ActsAsGenericController::ModelIncludes
|
5
6
|
ActionController::Base.send :include, QM::ActsAsGenericController::ControllerIncludes
|
7
|
+
ActionView::Base.send :include, QM::ActsAsGenericController::ViewIncludes
|
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: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 10
|
10
|
+
version: 0.0.10
|
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-08-
|
18
|
+
date: 2010-08-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- app/views/generic_controller/show.erb
|
82
82
|
- lib/qm-acts-as-generic-controller-controller.rb
|
83
83
|
- lib/qm-acts-as-generic-controller-model.rb
|
84
|
+
- lib/qm-acts-as-generic-controller-view.rb
|
84
85
|
- lib/qm-acts-as-generic-controller.rb
|
85
86
|
- README.rdoc
|
86
87
|
has_rdoc: true
|