dm-is-select 0.0.9 → 1.2.0
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/.gitignore +36 -12
- data/Gemfile +23 -0
- data/Guardfile +13 -0
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.rdoc +32 -7
- data/Rakefile +33 -69
- data/VERSION +1 -1
- data/dm-is-select.gemspec +94 -44
- data/docs/apple-touch-icon.png +0 -0
- data/docs/classes/DataMapper.html +81 -0
- data/docs/classes/DataMapper/Is.html +81 -0
- data/docs/classes/DataMapper/Is/Select.html +205 -0
- data/docs/classes/DataMapper/Is/Select/ClassMethods.html +258 -0
- data/docs/created.rid +4 -0
- data/docs/css/github.css +129 -0
- data/docs/css/main.css +333 -0
- data/docs/css/panel.css +384 -0
- data/docs/css/reset.css +48 -0
- data/docs/favicon.ico +0 -0
- data/docs/files/README_rdoc.html +272 -0
- data/docs/files/lib/dm-is-select_rb.html +88 -0
- data/docs/files/lib/is/select_rb.html +94 -0
- data/docs/i/arrows.png +0 -0
- data/docs/i/results_bg.png +0 -0
- data/docs/i/tree_bg.png +0 -0
- data/docs/index.html +13 -0
- data/docs/js/highlight.pack.js +1 -0
- data/docs/js/jquery-1.3.2.min.js +19 -0
- data/docs/js/jquery-effect.js +593 -0
- data/docs/js/main.js +24 -0
- data/docs/js/navigation.js +142 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/searchdoc.js +449 -0
- data/docs/js/searcher.js +228 -0
- data/docs/panel/index.html +73 -0
- data/docs/panel/links.html +12 -0
- data/docs/panel/tree.js +1 -0
- data/lib/dm-is-select.rb +5 -11
- data/lib/{dm-is-select/is → is}/select.rb +12 -10
- data/spec/{integration/select_spec.rb → dm-is-select_spec.rb} +25 -13
- data/spec/spec_helper.rb +10 -8
- metadata +278 -94
- data/History.rdoc +0 -24
- data/TODO +0 -0
- data/lib/dm-is-select/is/version.rb +0 -7
Binary file
|
@@ -0,0 +1,81 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>DataMapper</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
|
10
|
+
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
|
11
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="banner">
|
20
|
+
|
21
|
+
<h1>
|
22
|
+
<span class="type">Module</span>
|
23
|
+
DataMapper
|
24
|
+
|
25
|
+
</h1>
|
26
|
+
<ul class="files">
|
27
|
+
|
28
|
+
<li><a href="../files/lib/is/select_rb.html">lib/is/select.rb</a></li>
|
29
|
+
|
30
|
+
</ul>
|
31
|
+
</div>
|
32
|
+
<div id="bodyContent">
|
33
|
+
<div id="content">
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
<!-- Namespace -->
|
46
|
+
<div class="sectiontitle">Namespace</div>
|
47
|
+
<ul>
|
48
|
+
|
49
|
+
<li>
|
50
|
+
<span class="type">MODULE</span>
|
51
|
+
<a href="DataMapper/Is.html">DataMapper::Is</a>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
</ul>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
<!-- Methods -->
|
77
|
+
</div>
|
78
|
+
|
79
|
+
</div>
|
80
|
+
</body>
|
81
|
+
</html>
|
@@ -0,0 +1,81 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>DataMapper::Is</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
|
10
|
+
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
|
11
|
+
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="banner">
|
20
|
+
|
21
|
+
<h1>
|
22
|
+
<span class="type">Module</span>
|
23
|
+
DataMapper::Is
|
24
|
+
|
25
|
+
</h1>
|
26
|
+
<ul class="files">
|
27
|
+
|
28
|
+
<li><a href="../../files/lib/is/select_rb.html">lib/is/select.rb</a></li>
|
29
|
+
|
30
|
+
</ul>
|
31
|
+
</div>
|
32
|
+
<div id="bodyContent">
|
33
|
+
<div id="content">
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
<!-- Namespace -->
|
46
|
+
<div class="sectiontitle">Namespace</div>
|
47
|
+
<ul>
|
48
|
+
|
49
|
+
<li>
|
50
|
+
<span class="type">MODULE</span>
|
51
|
+
<a href="Is/Select.html">DataMapper::Is::Select</a>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
</ul>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
<!-- Methods -->
|
77
|
+
</div>
|
78
|
+
|
79
|
+
</div>
|
80
|
+
</body>
|
81
|
+
</html>
|
@@ -0,0 +1,205 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>DataMapper::Is::Select</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
|
10
|
+
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
|
11
|
+
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="banner">
|
20
|
+
|
21
|
+
<h1>
|
22
|
+
<span class="type">Module</span>
|
23
|
+
DataMapper::Is::Select
|
24
|
+
|
25
|
+
</h1>
|
26
|
+
<ul class="files">
|
27
|
+
|
28
|
+
<li><a href="../../../files/lib/is/select_rb.html">lib/is/select.rb</a></li>
|
29
|
+
|
30
|
+
</ul>
|
31
|
+
</div>
|
32
|
+
<div id="bodyContent">
|
33
|
+
<div id="content">
|
34
|
+
|
35
|
+
<div class="description">
|
36
|
+
|
37
|
+
<h1 id="label-dm-is-select">dm-is-select</h1>
|
38
|
+
|
39
|
+
<p>A <a href="../../DataMapper.html">DataMapper</a> plugin that makes getting
|
40
|
+
the <code><select></code> options from a Model easier.</p>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
<!-- Namespace -->
|
55
|
+
<div class="sectiontitle">Namespace</div>
|
56
|
+
<ul>
|
57
|
+
|
58
|
+
<li>
|
59
|
+
<span class="type">MODULE</span>
|
60
|
+
<a href="Select/ClassMethods.html">DataMapper::Is::Select::ClassMethods</a>
|
61
|
+
</li>
|
62
|
+
|
63
|
+
</ul>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
<!-- Method ref -->
|
69
|
+
<div class="sectiontitle">Methods</div>
|
70
|
+
<dl class="methods">
|
71
|
+
|
72
|
+
<dt>I</dt>
|
73
|
+
<dd>
|
74
|
+
<ul>
|
75
|
+
|
76
|
+
|
77
|
+
<li>
|
78
|
+
<a href="#method-i-is_select">is_select</a>
|
79
|
+
</li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
</dd>
|
83
|
+
|
84
|
+
</dl>
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
<!-- Section constants -->
|
99
|
+
<div class="sectiontitle">Constants</div>
|
100
|
+
<table border='0' cellpadding='5'>
|
101
|
+
|
102
|
+
<tr valign='top'>
|
103
|
+
<td class="attr-name">VERSION</td>
|
104
|
+
<td>=</td>
|
105
|
+
<td class="attr-value">IO.read("#{File.dirname(__FILE__)}/../../VERSION").chomp</td>
|
106
|
+
</tr>
|
107
|
+
|
108
|
+
<tr valign='top'>
|
109
|
+
<td> </td>
|
110
|
+
<td colspan="2" class="attr-desc"></td>
|
111
|
+
</tr>
|
112
|
+
|
113
|
+
|
114
|
+
</table>
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<!-- Methods -->
|
122
|
+
|
123
|
+
<div class="sectiontitle">Instance Public methods</div>
|
124
|
+
|
125
|
+
<div class="method">
|
126
|
+
<div class="title method-title" id="method-i-is_select">
|
127
|
+
|
128
|
+
<b>is_select</b>(select_field = :name, options = {})
|
129
|
+
|
130
|
+
<a href="../../../classes/DataMapper/Is/Select.html#method-i-is_select" name="method-i-is_select" class="permalink">Link</a>
|
131
|
+
</div>
|
132
|
+
|
133
|
+
|
134
|
+
<div class="description">
|
135
|
+
<p>Defines the field to use for the select menu</p>
|
136
|
+
|
137
|
+
<h4 id="method-i-is_select-label-Params+">Params </h4>
|
138
|
+
<ul><li>
|
139
|
+
<p>:field_name => the name of the field values shown in select</p>
|
140
|
+
</li><li>
|
141
|
+
<p>:options</p>
|
142
|
+
<ul><li>
|
143
|
+
<p>:is_tree => whether if the current Model is an is :tree model.
|
144
|
+
(Defaults to false)</p>
|
145
|
+
</li></ul>
|
146
|
+
</li></ul>
|
147
|
+
|
148
|
+
<h4 id="method-i-is_select-label-Examples">Examples</h4>
|
149
|
+
|
150
|
+
<pre class="ruby"><span class="ruby-identifier">is</span> :<span class="ruby-identifier">select</span>, :<span class="ruby-identifier">name</span>
|
151
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">creates</span> <span class="ruby-identifier">a</span> <span class="ruby-operator"><</span><span class="ruby-identifier">select</span><span class="ruby-operator">></span> <span class="ruby-identifier">options</span> <span class="ruby-identifier">array</span> <span class="ruby-identifier">on</span> <span class="ruby-identifier">the</span> :<span class="ruby-identifier">name</span> <span class="ruby-identifier">attribute</span> <span class="ruby-identifier">of</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">model</span>
|
152
|
+
|
153
|
+
<span class="ruby-identifier">is</span> :<span class="ruby-identifier">select</span>, :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">is_tree</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>
|
154
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">creates</span> <span class="ruby-identifier">a</span> <span class="ruby-operator"><</span><span class="ruby-identifier">select</span><span class="ruby-operator">></span> <span class="ruby-identifier">options</span> <span class="ruby-identifier">array</span> <span class="ruby-identifier">with</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">results</span> <span class="ruby-identifier">ordered</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">hierarchical</span> <span class="ruby-identifier">order</span>
|
155
|
+
<span class="ruby-identifier">parent</span> <span class="ruby-operator">></span> <span class="ruby-identifier">child</span> <span class="ruby-operator">></span> <span class="ruby-identifier">grandchild</span> <span class="ruby-keyword">for</span> <span class="ruby-identifier">each</span> <span class="ruby-identifier">parent</span>
|
156
|
+
|
157
|
+
<span class="ruby-identifier">is</span> :<span class="ruby-identifier">select</span>, :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">value_field</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">code</span>
|
158
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">creates</span> <span class="ruby-identifier">a</span> <span class="ruby-operator"><</span><span class="ruby-identifier">select</span><span class="ruby-operator">></span> <span class="ruby-identifier">options</span> <span class="ruby-identifier">array</span> <span class="ruby-identifier">with</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">results</span> <span class="ruby-identifier">ordered</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">hierarchical</span> <span class="ruby-identifier">order</span>
|
159
|
+
<span class="ruby-identifier">parent</span> <span class="ruby-operator">></span> <span class="ruby-identifier">child</span> <span class="ruby-operator">></span> <span class="ruby-identifier">grandchild</span> <span class="ruby-keyword">for</span> <span class="ruby-identifier">each</span> <span class="ruby-identifier">parent</span>
|
160
|
+
</pre>
|
161
|
+
|
162
|
+
<p>@api public</p>
|
163
|
+
</div>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
<div class="sourcecode">
|
171
|
+
|
172
|
+
<p class="source-link">
|
173
|
+
Source:
|
174
|
+
<a href="javascript:toggleSource('method-i-is_select_source')" id="l_method-i-is_select_source">show</a>
|
175
|
+
|
176
|
+
</p>
|
177
|
+
<div id="method-i-is_select_source" class="dyn-source">
|
178
|
+
<pre><span class="ruby-comment"># File lib/is/select.rb, line 39</span>
|
179
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">is_select</span>(<span class="ruby-identifier">select_field</span> = <span class="ruby-value">:name</span>, <span class="ruby-identifier">options</span> = {})
|
180
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"The :select_field, must be an existing attribute in the Model. Got [ #{select_field.inspect} ]"</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">properties</span>.<span class="ruby-identifier">any?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">select_field</span>.<span class="ruby-identifier">to_sym</span> }
|
181
|
+
|
182
|
+
<span class="ruby-ivar">@select_options</span> = {
|
183
|
+
<span class="ruby-value">:value_field</span> =<span class="ruby-operator">></span> <span class="ruby-string">"id"</span>,
|
184
|
+
<span class="ruby-comment"># add specical features if we are working with Tree Model</span>
|
185
|
+
<span class="ruby-value">:is_tree</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span>
|
186
|
+
}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
|
187
|
+
|
188
|
+
<span class="ruby-ivar">@select_field</span> = <span class="ruby-identifier">select_field</span>
|
189
|
+
<span class="ruby-ivar">@value_field</span> = <span class="ruby-ivar">@select_options</span>[<span class="ruby-value">:value_field</span>]
|
190
|
+
|
191
|
+
|
192
|
+
<span class="ruby-comment"># Add class & Instance methods</span>
|
193
|
+
<span class="ruby-identifier">extend</span> <span class="ruby-constant">DataMapper</span><span class="ruby-operator">::</span><span class="ruby-constant">Is</span><span class="ruby-operator">::</span><span class="ruby-constant">Select</span><span class="ruby-operator">::</span><span class="ruby-constant">ClassMethods</span>
|
194
|
+
<span class="ruby-comment"># include DataMapper::Is::Select::InstanceMethods</span>
|
195
|
+
|
196
|
+
<span class="ruby-keyword">end</span></pre>
|
197
|
+
</div>
|
198
|
+
</div>
|
199
|
+
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
|
203
|
+
</div>
|
204
|
+
</body>
|
205
|
+
</html>
|
@@ -0,0 +1,258 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>DataMapper::Is::Select::ClassMethods</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
|
10
|
+
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
|
11
|
+
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="banner">
|
20
|
+
|
21
|
+
<h1>
|
22
|
+
<span class="type">Module</span>
|
23
|
+
DataMapper::Is::Select::ClassMethods
|
24
|
+
|
25
|
+
</h1>
|
26
|
+
<ul class="files">
|
27
|
+
|
28
|
+
<li><a href="../../../../files/lib/is/select_rb.html">lib/is/select.rb</a></li>
|
29
|
+
|
30
|
+
</ul>
|
31
|
+
</div>
|
32
|
+
<div id="bodyContent">
|
33
|
+
<div id="content">
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
<!-- Method ref -->
|
49
|
+
<div class="sectiontitle">Methods</div>
|
50
|
+
<dl class="methods">
|
51
|
+
|
52
|
+
<dt>I</dt>
|
53
|
+
<dd>
|
54
|
+
<ul>
|
55
|
+
|
56
|
+
|
57
|
+
<li>
|
58
|
+
<a href="#method-i-items_for_select_menu">items_for_select_menu</a>
|
59
|
+
</li>
|
60
|
+
|
61
|
+
</ul>
|
62
|
+
</dd>
|
63
|
+
|
64
|
+
</dl>
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<!-- Section attributes -->
|
82
|
+
<div class="sectiontitle">Attributes</div>
|
83
|
+
<table border='0' cellpadding='5'>
|
84
|
+
|
85
|
+
<tr valign='top'>
|
86
|
+
<td class='attr-rw'>
|
87
|
+
[R]
|
88
|
+
</td>
|
89
|
+
<td class='attr-name'>select_field</td>
|
90
|
+
<td class='attr-desc'></td>
|
91
|
+
</tr>
|
92
|
+
|
93
|
+
<tr valign='top'>
|
94
|
+
<td class='attr-rw'>
|
95
|
+
[R]
|
96
|
+
</td>
|
97
|
+
<td class='attr-name'>select_options</td>
|
98
|
+
<td class='attr-desc'></td>
|
99
|
+
</tr>
|
100
|
+
|
101
|
+
<tr valign='top'>
|
102
|
+
<td class='attr-rw'>
|
103
|
+
[R]
|
104
|
+
</td>
|
105
|
+
<td class='attr-name'>value_field</td>
|
106
|
+
<td class='attr-desc'></td>
|
107
|
+
</tr>
|
108
|
+
|
109
|
+
</table>
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
<!-- Methods -->
|
114
|
+
|
115
|
+
<div class="sectiontitle">Instance Public methods</div>
|
116
|
+
|
117
|
+
<div class="method">
|
118
|
+
<div class="title method-title" id="method-i-items_for_select_menu">
|
119
|
+
|
120
|
+
<b>items_for_select_menu</b>(options = {})
|
121
|
+
|
122
|
+
<a href="../../../../classes/DataMapper/Is/Select/ClassMethods.html#method-i-items_for_select_menu" name="method-i-items_for_select_menu" class="permalink">Link</a>
|
123
|
+
</div>
|
124
|
+
|
125
|
+
|
126
|
+
<div class="description">
|
127
|
+
<p>Provides the Model content in a ready to use <code><select></code>
|
128
|
+
options array</p>
|
129
|
+
|
130
|
+
<h4 id="method-i-items_for_select_menu-label-Params">Params</h4>
|
131
|
+
<ul><li>
|
132
|
+
<p>:options</p>
|
133
|
+
<ul><li>
|
134
|
+
<p>:prompt [String/Boolean] => The text shown on the
|
135
|
+
<code><select></code> field in the browser. (Defaults to “<a
|
136
|
+
href="../Select.html">Select</a> NameOfYourModel”)</p>
|
137
|
+
</li><li>
|
138
|
+
<p>:divider [Boolean] => Whether to add a divider/separator between the
|
139
|
+
prompt and the main options. (Defaults to <code>true</code>)</p>
|
140
|
+
</li><li>
|
141
|
+
<p>:order [Array] => A normal DM order declaration. (Defaults to [:name]
|
142
|
+
or the name of the <a
|
143
|
+
href="ClassMethods.html#attribute-i-select_field">#select_field</a>
|
144
|
+
declared)</p>
|
145
|
+
</li><li>
|
146
|
+
<p>:show_root [Boolean] => Whether to add the Top Level Parent in the
|
147
|
+
choices. (Defaults to <code>true</code>)</p>
|
148
|
+
</li><li>
|
149
|
+
<p>:root_text [String] => The text to show as the Parent item in select
|
150
|
+
list. (Defaults to “Top Level NameOfYourModel”)</p>
|
151
|
+
</li></ul>
|
152
|
+
</li></ul>
|
153
|
+
|
154
|
+
<h4 id="method-i-items_for_select_menu-label-Examples">Examples</h4>
|
155
|
+
|
156
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>
|
157
|
+
=<span class="ruby-operator">></span> [ [<span class="ruby-keyword">nil</span>, <span class="ruby-string">'Select Category'</span>], [<span class="ruby-keyword">nil</span>, <span class="ruby-string">'---'</span>], [<span class="ruby-value">1</span>, <span class="ruby-string">'Category 1'</span>] ,<span class="ruby-operator">...</span>.]
|
158
|
+
|
159
|
+
<span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">prompt</span> =<span class="ruby-operator">></span> <span class="ruby-string">"Custom Prompt"</span>)
|
160
|
+
=<span class="ruby-operator">></span> [ [<span class="ruby-keyword">nil</span>, <span class="ruby-string">'Custom Prompt'</span>],<span class="ruby-operator">...</span>]
|
161
|
+
|
162
|
+
<span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">prompt</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span>)
|
163
|
+
=<span class="ruby-operator">></span> [ [<span class="ruby-value">1</span>, <span class="ruby-string">'Category 1'</span>] ,<span class="ruby-operator">...</span>]
|
164
|
+
|
165
|
+
<span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">divider</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span> )
|
166
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">array</span> <span class="ruby-identifier">without</span> <span class="ruby-identifier">the</span> [<span class="ruby-keyword">nil</span>, <span class="ruby-string">'---'</span>] <span class="ruby-identifier">node</span>
|
167
|
+
|
168
|
+
<span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">order</span> =<span class="ruby-operator">></span> [ :<span class="ruby-identifier">id</span>.<span class="ruby-identifier">desc</span> ] )
|
169
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">array</span> <span class="ruby-identifier">with</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">order</span> <span class="ruby-identifier">reversed</span>. (<span class="ruby-constant">Prompts</span> & <span class="ruby-identifier">divider</span> <span class="ruby-identifier">always</span> <span class="ruby-identifier">comes</span> <span class="ruby-identifier">first</span>)
|
170
|
+
|
171
|
+
<span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">publish_status</span> =<span class="ruby-operator">></span> <span class="ruby-string">"on"</span>, :<span class="ruby-identifier">order</span> =<span class="ruby-operator">></span> [ :<span class="ruby-identifier">id</span>.<span class="ruby-identifier">desc</span> ] )
|
172
|
+
=<span class="ruby-operator">></span> <span class="ruby-identifier">returns</span> <span class="ruby-identifier">only</span> <span class="ruby-identifier">those</span> <span class="ruby-identifier">items</span> <span class="ruby-identifier">that</span> <span class="ruby-identifier">matches</span> <span class="ruby-identifier">the</span> <span class="ruby-identifier">query</span> <span class="ruby-identifier">params</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">just</span> <span class="ruby-identifier">an</span> <span class="ruby-identifier">empty</span> <span class="ruby-constant">Select</span> <span class="ruby-constant">Menu</span>
|
173
|
+
</pre>
|
174
|
+
|
175
|
+
<p>If your model is a Tree:</p>
|
176
|
+
|
177
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">root_text</span> =<span class="ruby-operator">></span> <span class="ruby-string">"Custom Root Text"</span>) <span class="ruby-comment"># sets the text for the Top Level (root) Parent</span>
|
178
|
+
=<span class="ruby-operator">></span> [ <span class="ruby-operator">...</span>, [<span class="ruby-value">0</span>, <span class="ruby-string">'Custom Root Text'</span>],<span class="ruby-operator">...</span>]
|
179
|
+
|
180
|
+
<span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>(:<span class="ruby-identifier">show_root</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span>) <span class="ruby-comment"># removes the Top Level (root) Parent from the</span>
|
181
|
+
</pre>
|
182
|
+
|
183
|
+
<p>@api public</p>
|
184
|
+
</div>
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
<div class="sourcecode">
|
192
|
+
|
193
|
+
<p class="source-link">
|
194
|
+
Source:
|
195
|
+
<a href="javascript:toggleSource('method-i-items_for_select_menu_source')" id="l_method-i-items_for_select_menu_source">show</a>
|
196
|
+
|
197
|
+
</p>
|
198
|
+
<div id="method-i-items_for_select_menu_source" class="dyn-source">
|
199
|
+
<pre><span class="ruby-comment"># File lib/is/select.rb, line 102</span>
|
200
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">items_for_select_menu</span>(<span class="ruby-identifier">options</span> = {})
|
201
|
+
<span class="ruby-comment"># clean out the various parts</span>
|
202
|
+
<span class="ruby-identifier">html_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-value">:prompt</span>, <span class="ruby-value">:divider</span>, <span class="ruby-value">:show_root</span>, <span class="ruby-value">:root_text</span>)
|
203
|
+
<span class="ruby-identifier">sql_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">except</span>(<span class="ruby-value">:prompt</span>, <span class="ruby-value">:divider</span>, <span class="ruby-value">:show_root</span>, <span class="ruby-value">:root_text</span>)
|
204
|
+
|
205
|
+
<span class="ruby-comment"># defaults</span>
|
206
|
+
<span class="ruby-identifier">html_options</span> = {
|
207
|
+
<span class="ruby-value">:prompt</span> =<span class="ruby-operator">></span> <span class="ruby-node">"Select #{self.name}"</span>,
|
208
|
+
<span class="ruby-value">:divider</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>,
|
209
|
+
<span class="ruby-value">:show_root</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>,
|
210
|
+
<span class="ruby-value">:root_text</span> =<span class="ruby-operator">></span> <span class="ruby-node">"Top Level #{self.name}"</span>,
|
211
|
+
}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>)
|
212
|
+
|
213
|
+
<span class="ruby-identifier">sql_options</span> = {
|
214
|
+
<span class="ruby-value">:order</span> =<span class="ruby-operator">></span> [<span class="ruby-keyword">self</span>.<span class="ruby-identifier">select_field</span>.<span class="ruby-identifier">to_sym</span>],
|
215
|
+
}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">sql_options</span>)
|
216
|
+
|
217
|
+
<span class="ruby-identifier">mi</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">select_options</span>[<span class="ruby-value">:is_tree</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">all</span>({ <span class="ruby-value">:parent_id</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span> }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">sql_options</span>) ) <span class="ruby-operator">:</span> <span class="ruby-identifier">all</span>(<span class="ruby-identifier">sql_options</span>)
|
218
|
+
|
219
|
+
<span class="ruby-identifier">res</span> = []
|
220
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:prompt</span>]
|
221
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:prompt</span>]]
|
222
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-string">'nil'</span>, <span class="ruby-string">" ------ "</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:divider</span>]
|
223
|
+
<span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">select_options</span>[<span class="ruby-value">:is_tree</span>]
|
224
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:show_root</span>]
|
225
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-number">0</span>, <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:root_text</span>]]
|
226
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-string">'nil'</span>,<span class="ruby-string">" ------ "</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">html_options</span>[<span class="ruby-value">:divider</span>]
|
227
|
+
<span class="ruby-keyword">end</span>
|
228
|
+
<span class="ruby-keyword">end</span>
|
229
|
+
<span class="ruby-keyword">end</span>
|
230
|
+
|
231
|
+
<span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">select_options</span>[<span class="ruby-value">:is_tree</span>]
|
232
|
+
<span class="ruby-identifier">mi</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
|
233
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">value_field</span>), <span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">select_field</span>)]
|
234
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">blank?</span>
|
235
|
+
<span class="ruby-identifier">x</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span>
|
236
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">child</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">value_field</span>), <span class="ruby-node">"-- #{child.send(self.select_field)}"</span>]
|
237
|
+
<span class="ruby-identifier">child</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">grand_child</span><span class="ruby-operator">|</span>
|
238
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [ <span class="ruby-identifier">grand_child</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">value_field</span>), <span class="ruby-node">"-- -- #{grand_child.send(self.select_field)}"</span>]
|
239
|
+
<span class="ruby-keyword">end</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">blank?</span>
|
240
|
+
<span class="ruby-keyword">end</span>
|
241
|
+
<span class="ruby-keyword">end</span>
|
242
|
+
<span class="ruby-keyword">end</span>
|
243
|
+
<span class="ruby-keyword">else</span>
|
244
|
+
<span class="ruby-identifier">mi</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
|
245
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">value_field</span>), <span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">select_field</span>)]
|
246
|
+
<span class="ruby-keyword">end</span>
|
247
|
+
<span class="ruby-keyword">end</span>
|
248
|
+
<span class="ruby-identifier">res</span>
|
249
|
+
<span class="ruby-keyword">end</span></pre>
|
250
|
+
</div>
|
251
|
+
</div>
|
252
|
+
|
253
|
+
</div>
|
254
|
+
</div>
|
255
|
+
|
256
|
+
</div>
|
257
|
+
</body>
|
258
|
+
</html>
|