sortable_skima 0.2.0.25

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +192 -0
  3. data/app/assets/javascripts/jquery-ui.min.js +12 -0
  4. data/app/assets/javascripts/jquery.ba-bbq.js +1137 -0
  5. data/app/assets/javascripts/skima-sortable-tables_2_0_10.js +450 -0
  6. data/app/assets/stylesheets/images/animated-overlay.gif +0 -0
  7. data/app/assets/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  8. data/app/assets/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  9. data/app/assets/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  10. data/app/assets/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  11. data/app/assets/stylesheets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  12. data/app/assets/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  13. data/app/assets/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  14. data/app/assets/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  15. data/app/assets/stylesheets/images/ui-icons_222222_256x240.png +0 -0
  16. data/app/assets/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
  17. data/app/assets/stylesheets/images/ui-icons_454545_256x240.png +0 -0
  18. data/app/assets/stylesheets/images/ui-icons_888888_256x240.png +0 -0
  19. data/app/assets/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
  20. data/app/assets/stylesheets/jquery-ui.css +1183 -0
  21. data/app/controllers/sortables_controller.rb +75 -0
  22. data/app/models/sortable.rb +82 -0
  23. data/config/routes.rb +5 -0
  24. data/doc/Backtrace.html +493 -0
  25. data/doc/README_rdoc.html +329 -0
  26. data/doc/SortableHelper.html +364 -0
  27. data/doc/SortableSkima.html +343 -0
  28. data/doc/SortableSkima/Engine.html +131 -0
  29. data/doc/created.rid +7 -0
  30. data/doc/images/add.png +0 -0
  31. data/doc/images/brick.png +0 -0
  32. data/doc/images/brick_link.png +0 -0
  33. data/doc/images/bug.png +0 -0
  34. data/doc/images/bullet_black.png +0 -0
  35. data/doc/images/bullet_toggle_minus.png +0 -0
  36. data/doc/images/bullet_toggle_plus.png +0 -0
  37. data/doc/images/date.png +0 -0
  38. data/doc/images/delete.png +0 -0
  39. data/doc/images/find.png +0 -0
  40. data/doc/images/loadingAnimation.gif +0 -0
  41. data/doc/images/macFFBgHack.png +0 -0
  42. data/doc/images/package.png +0 -0
  43. data/doc/images/page_green.png +0 -0
  44. data/doc/images/page_white_text.png +0 -0
  45. data/doc/images/page_white_width.png +0 -0
  46. data/doc/images/plugin.png +0 -0
  47. data/doc/images/ruby.png +0 -0
  48. data/doc/images/tag_blue.png +0 -0
  49. data/doc/images/tag_green.png +0 -0
  50. data/doc/images/transparent.png +0 -0
  51. data/doc/images/wrench.png +0 -0
  52. data/doc/images/wrench_orange.png +0 -0
  53. data/doc/images/zoom.png +0 -0
  54. data/doc/index.html +347 -0
  55. data/doc/js/darkfish.js +155 -0
  56. data/doc/js/jquery.js +18 -0
  57. data/doc/js/navigation.js +142 -0
  58. data/doc/js/search.js +94 -0
  59. data/doc/js/search_index.js +1 -0
  60. data/doc/js/searcher.js +228 -0
  61. data/doc/rdoc.css +543 -0
  62. data/doc/sortable_parser.html +78 -0
  63. data/doc/table_of_contents.html +114 -0
  64. data/lib/sortable_skima.rb +122 -0
  65. data/lib/sortable_skima/active_record.rb +36 -0
  66. data/lib/sortable_skima/backtrace.rb +53 -0
  67. data/lib/sortable_skima/engine.rb +63 -0
  68. data/lib/sortable_skima/helpers/sortable_helper.rb +188 -0
  69. metadata +142 -0
@@ -0,0 +1,329 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>README - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body class="file">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="project-metadata">
47
+ <nav id="fileindex-section" class="section project-section">
48
+ <h3 class="section-header">Pages</h3>
49
+
50
+ <ul>
51
+
52
+ <li class="file"><a href="./README_rdoc.html">README</a>
53
+
54
+ </ul>
55
+ </nav>
56
+
57
+ <nav id="classindex-section" class="section project-section">
58
+ <h3 class="section-header">Class and Module Index</h3>
59
+
60
+ <ul class="link-list">
61
+
62
+ <li><a href="./SortableSkima.html">SortableSkima</a>
63
+
64
+ <li><a href="./SortableSkima/Engine.html">SortableSkima::Engine</a>
65
+
66
+ <li><a href="./Backtrace.html">Backtrace</a>
67
+
68
+ <li><a href="./SortableHelper.html">SortableHelper</a>
69
+
70
+ </ul>
71
+ </nav>
72
+
73
+ </div>
74
+ </nav>
75
+
76
+ <div id="documentation" class="description">
77
+
78
+ <h1 id="label-SortableSkima"><a href="SortableSkima.html">SortableSkima</a></h1>
79
+
80
+ <h2 id="label-Description">Description</h2>
81
+
82
+ <p>This gem aids in building sortable and filtrable tables with both local or
83
+ remote sources.</p>
84
+
85
+ <p>Table contents are loaded by ajax.</p>
86
+
87
+ <h2 id="label-Installation">Installation</h2>
88
+
89
+ <p>Add this line to your application’s Gemfile:</p>
90
+
91
+ <pre>source 'http://whatever:skimaisdabomb@gems.skima.net' do
92
+ gem &quot;sortable_skima&quot;
93
+ end</pre>
94
+
95
+ <p>Run:</p>
96
+
97
+ <pre>$ bundle</pre>
98
+
99
+ <p>Create both backtraces and sortables migrations if you dont have them
100
+ already in your db</p>
101
+
102
+ <pre class="ruby"><span class="ruby-identifier">create_table</span> :<span class="ruby-identifier">sortables</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
103
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">text</span> :<span class="ruby-identifier">query</span>
104
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">timestamps</span>
105
+ <span class="ruby-keyword">end</span>
106
+ <span class="ruby-identifier">create_table</span> :<span class="ruby-identifier">backtraces</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
107
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">integer</span> :<span class="ruby-identifier">user_id</span>
108
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">string</span> :<span class="ruby-identifier">action</span>
109
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">string</span> :<span class="ruby-identifier">value</span>
110
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">timestamps</span>
111
+ <span class="ruby-keyword">end</span>
112
+ </pre>
113
+ <hr style="height: 1px">
114
+
115
+ <h1 id="label-Tables">Tables</h1>
116
+
117
+ <h2 id="label-Example+usage">Example usage</h2>
118
+
119
+ <pre>&lt;%= sortable_table_tag 'Project.select(&quot;projects.*, COUNT(warnings.id) as warnings_count&quot;).joins(&quot;LEFT JOIN users ON users.id = projects.manager_id '+
120
+ 'LEFT JOIN divisions ON divisions.id = projects.division_id '+
121
+ 'LEFT JOIN budgets ON budgets.project_id = projects.id AND budgets.active '+
122
+ 'LEFT JOIN budget_stats ON budget_stats.budget_id = budgets.id '+
123
+ 'LEFT JOIN project_types ON project_types.id = projects.project_type_id '+
124
+ 'LEFT JOIN warnings ON warnings.warnable_type = \'Project\' AND warnings.warnable_id = projects.id&quot;)'+
125
+ '.joins( :project_stats).group(&quot;projects.id&quot;)',[
126
+ {:sort_field=&gt;'projects.id',:title=&gt;'Name',:display_method=&gt;&quot;summary&quot;,:path_method=&gt;&quot;project_path(model)&quot;,:td_class=&gt;'align_center', :style=&gt;'width: 200px;'},
127
+ {:sort_field=&gt;'manager_id',:title=&gt;'Manager',:display_method=&gt;&quot;manager.nil? ? '---' : manager.username&quot;,:path_method=&gt;&quot;model.manager.nil? ? nil : user_path(model.manager)&quot;,:td_class=&gt;'align_center', :style=&gt;'width: 70px;'},
128
+ {:sort_field=&gt;'divisions.name',:title=&gt;'Unit',:display_method=&gt;'division.name rescue &quot;---&quot;',:td_class=&gt;'align_center',:style=&gt;'width: 100px;'},
129
+ {:sort_field=&gt;'nature',:title=&gt;'Nature',:display_method=&gt;'nature',:td_class=&gt;'align_center',:style=&gt;'width: 70px;'},
130
+ {:sort_field=&gt;'project_types.name',:title=&gt;'Type',:display_method=&gt;'project_type.name',:td_class=&gt;'align_center',:style=&gt;'width: 70px;'},
131
+ {:sort_field=&gt;'status',:title=&gt;'Status',:display_method=&gt;'get_status',:td_class=&gt;'align_center',:style=&gt;'width: 70px;'},
132
+ {:sort_field=&gt;'warnings_count',:title=&gt;'Alarms',:display_method=&gt;&quot;warnings_count&quot;,:td_class=&gt;'align_center',:style=&gt;'width: 70px;'},
133
+ {:sort_field=&gt;'price',:title=&gt;'Price',:display_method=&gt;&quot;price&quot;,:td_class=&gt;'align_center',:style=&gt;'width: 70px;'},
134
+ {:sort_field=&gt;'budget_stats.estimated_costs',:title=&gt;'Est. Cost',:display_method=&gt;&quot;active_budget.budget_stats.estimated_costs rescue '---'&quot;,:td_class=&gt;'align_center',:style=&gt;'width: 70px;'},
135
+ {:sort_field=&gt;'project_stats.actual_cost',:title=&gt;'Actual Cost',:display_method=&gt;&quot;project_stats.actual_cost&quot;,:style=&gt;'width: 90px;'},
136
+ {:sort_field=&gt;'progress',:title=&gt;'&lt;small&gt;Prog&lt;sup&gt;3&lt;/sup&gt;&lt;/small&gt;',:display_method=&gt;&quot;100 * project_stats.progress.round(2) if !project_stats.progress.nil?&quot;,:style=&gt;'width: 70px;'}
137
+ ],:items_per_page=&gt;12,
138
+ :class=&gt;'fixed_columns alternatingRows',
139
+ :style =&gt; &quot;padding-top:10px; padding-bottom:10px;&quot; %&gt;</pre>
140
+
141
+ <p>This will render a sortable table. with the given settings.</p>
142
+
143
+ <h3 id="label-Method+sortable_table_tag%28+base_query%2C+columns%3D%5B%5D%2C+opts%3D%7B%7D+%29">Method sortable_table_tag( base_query, columns=[], opts={} )</h3>
144
+ <dl class="rdoc-list label-list"><dt>Arguments
145
+ <dd><dl class="rdoc-list label-list"><dt>base_query
146
+ <dd>
147
+ <p>A string containing a set of rails commands that must return an
148
+ ActiveRecord::Relation.</p>
149
+
150
+ <p>The query must contain a reference to any tables that will be used in
151
+ either sorting or filtering either through a join() or an include().</p>
152
+
153
+ <p>NOTICE: a simple ‘join()’ will result in an INNER JOIN exluding any
154
+ unpaired results.</p>
155
+ </dd><dt>columns
156
+ <dd>
157
+ <p>An array of hashes representing each column in the table</p>
158
+
159
+ <p>The arguments for each column are:</p>
160
+ <dl class="rdoc-list label-list"><dt>:sort_field
161
+ <dd>
162
+ <p>The SQL field wich will be used for sorting this will be placed in the DB
163
+ query</p>
164
+ </dd><dt>:title
165
+ <dd>
166
+ <p>The title for the html table header, can contain html, if blank the
167
+ sort_field will be used</p>
168
+ </dd><dt>:display_method
169
+ <dd>
170
+ <p>The method to generate the content of each cell in the column, this is run
171
+ in each model instance, and has controller_context and view_context
172
+ available if needed</p>
173
+ </dd><dt>:path_method
174
+ <dd>
175
+ <p>The method used to generate an url which is then used to convert the cell
176
+ into an hyperlink, run in the controller context with the variable
177
+ ‘model’ available containing the model instance for each row</p>
178
+ </dd><dt>:no_display
179
+ <dd>
180
+ <p>This field wont be parsed to html.</p>
181
+
182
+ <p>Useful for when extra data is needed for JS or to pass specific CSS for
183
+ each row.</p>
184
+
185
+ <p>NOTICE: Possible bug if the no_display columns are not added after
186
+ displayed columns, untested.</p>
187
+ </dd><dt>:disabled
188
+ <dd>
189
+ <p>Boolean. Disables ordering on this column.</p>
190
+ </dd></dl>
191
+ </dd><dt>options
192
+ <dd><dl class="rdoc-list label-list"><dt>:default_order
193
+ <dd>
194
+ <p>Order to be used in case there is no order selected.</p>
195
+ </dd><dt>:items_per_page
196
+ <dd>
197
+ <p>For paginate. Defaults to 10.</p>
198
+ </dd><dt>:disable_backtrace
199
+ <dd>
200
+ <p>Boolean. Disables caching of the selected order and filters. Unstable.</p>
201
+ </dd><dt>:paginate
202
+ <dd>
203
+ <p>Boolean, default true. Enable pagination.</p>
204
+ </dd><dt>:group
205
+ <dd>
206
+ <p>String. ID of the table and filters group. For when there is more than one
207
+ sortable in the same page.</p>
208
+ </dd><dt>OTHER OPTIONS
209
+ <dd>
210
+ <p>All options accepted for a ‘content_tag’ helper. EX: :class, :style ,
211
+ :some_attribute</p>
212
+ </dd></dl>
213
+ </dd></dl>
214
+ </dd></dl>
215
+ <hr style="height: 1px">
216
+
217
+ <h1 id="label-Filters">Filters</h1>
218
+
219
+ <h2 id="label-Example">Example</h2>
220
+
221
+ <pre>Unit: &lt;%= sortable_filter_tag &quot;division_id&quot;, ['All']+Division.all.map{|x|[ x.name, x.id]}, :style =&gt; &quot;width:90px&quot;%&gt;
222
+ Status: &lt;%= sortable_filter_tag &quot;status&quot;, ['All']+Project::STATUSES, :style =&gt; &quot;width:90px&quot;%&gt;
223
+ Nature: &lt;%= sortable_filter_tag &quot;nature&quot;, ['All']+Project::TYPES, :style =&gt; &quot;width:90px;&quot;%&gt;
224
+ Type: &lt;%= sortable_filter_tag &quot;project_type_id&quot;, ['All']+ProjectType.all.map{|x|[ x.name, x.id]}, :style =&gt; &quot;width:90px&quot;%&gt;
225
+ Manager: &lt;%=sortable_filter_tag(&quot;manager_id&quot;, users, :style =&gt; &quot;width:90px&quot;) %&gt;</pre>
226
+
227
+ <h3 id="label-Method+sortable_filter_tag%28column_name%2C+options_list%2C++opts+%3D+%7B%7D%29">Method sortable_filter_tag(column_name, options_list, opts = {})</h3>
228
+ <dl class="rdoc-list label-list"><dt>Arguments
229
+ <dd><dl class="rdoc-list label-list"><dt>column_name
230
+ <dd>
231
+ <p>String with the SQL column to be used for filtering. (Discarded if :raw_sql
232
+ is true)</p>
233
+ </dd><dt>options_list
234
+ <dd>
235
+ <p>An array with 1 or 2 dimensions .</p>
236
+
237
+ <p>The first element ( <a href="http://i">ar</a>[0] ) is displayed the second
238
+ ( <a href="http://i">ar</a>[1] ) is the actual value to be matched. (
239
+ some_query.where(column_name =&gt; option_value) )</p>
240
+
241
+ <p>If it has only one dimension both values are the same.</p>
242
+
243
+ <p>If :raw_sql is true then the second element should contain a valid WHERE
244
+ condition. EX: ‘users.login_attempts &gt; 5’</p>
245
+ </dd><dt>opts
246
+ <dd><dl class="rdoc-list label-list"><dt>:raw_sql
247
+ <dd>
248
+ <p>Boolean. Defaults to false.</p>
249
+
250
+ <p>If true the value in the options list will be used literaly in the query (
251
+ some_query.where(option_value) )</p>
252
+ </dd><dt>:group
253
+ <dd>
254
+ <p>ID to match the one in the sortable table that is related to this filter.
255
+ For when there is more than one sortable in the same page.</p>
256
+ </dd><dt>:selected
257
+ <dd>
258
+ <p>The selected option. Must be the same as the option value.</p>
259
+ </dd><dt>OTHER OPTIONS
260
+ <dd>
261
+ <p>All options that are valid for a ‘select_tag’ helper</p>
262
+ </dd></dl>
263
+ </dd></dl>
264
+ </dd></dl>
265
+ <hr style="height: 1px">
266
+
267
+ <h2 id="label-Frontend">Frontend</h2>
268
+
269
+ <p>This gem has Javascript and CSS files included to make the tables work on
270
+ the browser</p>
271
+
272
+ <p>*These files are added automatically to config.default_js *</p>
273
+
274
+ <p>*These files must be present in your views for the frontend to work*</p>
275
+
276
+ <p>&gt; skima-sortable-tables.js &gt; ,jquery.ba.bbq.js &gt; ,jquery-ui.min.js
277
+ &gt; ,jquery-ui.css</p>
278
+ <dl class="rdoc-list label-list"><dt>Events
279
+ <dd><dl class="rdoc-list label-list"><dt>sortable.loaded
280
+ <dd>
281
+ <p>Fired after the table data has been loaded and rendered</p>
282
+
283
+ <p>Arguments passed with event</p>
284
+
285
+ <p>data: The data received for the table</p>
286
+
287
+ <p>$table: The table element Jquery reference</p>
288
+
289
+ <p>queryID: Unique identifier for the sortable query on the server</p>
290
+ </dd></dl>
291
+ </dd></dl>
292
+
293
+ <h2 id="label-Re-using+sortable+filters+and+orders">Re-using sortable filters and orders</h2>
294
+
295
+ <p>Catch the data loaded event in javascript</p>
296
+
297
+ <pre>$('your sortable table or document or whatever').on('sortable.loaded',someFunction);
298
+ function someFunction(evt, data, $tableElement, queryID){
299
+ //Send the reference to the query to the server
300
+ $.ajax({
301
+ url:'some_path'
302
+ data:{sortable_id:queryID}
303
+ })
304
+ }</pre>
305
+
306
+ <p>Then use the sortable filters in your controller</p>
307
+
308
+ <pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">some_action</span>
309
+ <span class="ruby-identifier">my_base_query</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">'some_rule'</span>)<span class="ruby-comment"># or User or User.order_by() or SomeModel.join() or whatever</span>
310
+ <span class="ruby-identifier">include_order</span> = <span class="ruby-keyword">false</span>
311
+ <span class="ruby-identifier">users</span> = <span class="ruby-constant">SortableSkima</span>.<span class="ruby-identifier">attach_sortables</span>( <span class="ruby-identifier">my_base_query</span>, <span class="ruby-identifier">params</span>[<span class="ruby-string">'sortable_id'</span>], <span class="ruby-identifier">cur_user_or_admin</span>, <span class="ruby-identifier">include_order</span>)
312
+
313
+ <span class="ruby-comment">#...do what you want with your results</span>
314
+ <span class="ruby-keyword">end</span>
315
+
316
+ <span class="ruby-operator">-</span><span class="ruby-operator">-</span><span class="ruby-operator">-</span>
317
+ </pre>
318
+
319
+
320
+ </div>
321
+
322
+
323
+
324
+ <footer id="validator-badges">
325
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
326
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
327
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
328
+ </footer>
329
+
@@ -0,0 +1,364 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>module SortableHelper - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="module">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/sortable_skima/helpers/sortable_helper.rb
51
+ </ul>
52
+ </nav>
53
+
54
+
55
+ </div>
56
+
57
+ <div id="class-metadata">
58
+
59
+
60
+
61
+ <!-- Method Quickref -->
62
+ <nav id="method-list-section" class="section">
63
+ <h3 class="section-header">Methods</h3>
64
+
65
+ <ul class="link-list">
66
+
67
+ <li><a href="#method-i-get_sortable">#get_sortable</a>
68
+
69
+ <li><a href="#method-i-sortable_filter_tag">#sortable_filter_tag</a>
70
+
71
+ <li><a href="#method-i-sortable_table_tag">#sortable_table_tag</a>
72
+
73
+ </ul>
74
+ </nav>
75
+
76
+ </div>
77
+
78
+ <div id="project-metadata">
79
+ <nav id="fileindex-section" class="section project-section">
80
+ <h3 class="section-header">Pages</h3>
81
+
82
+ <ul>
83
+
84
+ <li class="file"><a href="./README_rdoc.html">README</a>
85
+
86
+ </ul>
87
+ </nav>
88
+
89
+ <nav id="classindex-section" class="section project-section">
90
+ <h3 class="section-header">Class and Module Index</h3>
91
+
92
+ <ul class="link-list">
93
+
94
+ <li><a href="./SortableSkima.html">SortableSkima</a>
95
+
96
+ <li><a href="./SortableSkima/Engine.html">SortableSkima::Engine</a>
97
+
98
+ <li><a href="./Backtrace.html">Backtrace</a>
99
+
100
+ <li><a href="./SortableHelper.html">SortableHelper</a>
101
+
102
+ </ul>
103
+ </nav>
104
+
105
+ </div>
106
+ </nav>
107
+
108
+ <div id="documentation">
109
+ <h1 class="module">module SortableHelper</h1>
110
+
111
+ <div id="description" class="description">
112
+
113
+ </div><!-- description -->
114
+
115
+
116
+
117
+
118
+ <section id="5Buntitled-5D" class="documentation-section">
119
+
120
+
121
+
122
+
123
+
124
+ <!-- Constants -->
125
+ <section id="constants-list" class="section">
126
+ <h3 class="section-header">Constants</h3>
127
+ <dl>
128
+
129
+ <dt id="DEFAULT_GROUP">DEFAULT_GROUP
130
+
131
+ <dd class="description">
132
+
133
+
134
+ </dl>
135
+ </section>
136
+
137
+
138
+
139
+
140
+ <!-- Methods -->
141
+
142
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
143
+ <h3 class="section-header">Public Instance Methods</h3>
144
+
145
+
146
+ <div id="method-i-sortable_filter_tag" class="method-detail ">
147
+
148
+ <div class="method-heading">
149
+ <span class="method-name">sortable_filter_tag</span><span
150
+ class="method-args">(column_name, options_list, opts = {})</span>
151
+ <span class="method-click-advice">click to toggle source</span>
152
+ </div>
153
+
154
+
155
+ <div class="method-description">
156
+
157
+
158
+
159
+
160
+
161
+ <div class="method-source-code" id="sortable_filter_tag-source">
162
+ <pre><span class="ruby-comment"># File lib/sortable_skima/helpers/sortable_helper.rb, line 6</span>
163
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">sortable_filter_tag</span>(<span class="ruby-identifier">column_name</span>, <span class="ruby-identifier">options_list</span>, <span class="ruby-identifier">opts</span> = {})
164
+ <span class="ruby-identifier">opts</span> = {<span class="ruby-value">:raw_sql=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword">false</span>, <span class="ruby-value">:group=</span><span class="ruby-operator">&gt;</span><span class="ruby-constant">DEFAULT_GROUP</span>}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">opts</span>)
165
+
166
+ <span class="ruby-identifier">srtbl</span> = <span class="ruby-identifier">get_sortable</span> <span class="ruby-identifier">opts</span>
167
+
168
+ <span class="ruby-identifier">selected_value</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:selected_value</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:selected</span>)
169
+ <span class="ruby-identifier">selected_value_id</span> = <span class="ruby-keyword">nil</span>
170
+ <span class="ruby-identifier">opts</span>[<span class="ruby-value">:class</span>] = <span class="ruby-node">&quot;#{opts[:class]} sortable-filter&quot;</span>
171
+ <span class="ruby-identifier">filter_id</span> = <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">filters</span>.<span class="ruby-identifier">length</span>
172
+ <span class="ruby-identifier">options</span> = []
173
+ <span class="ruby-identifier">new_options_list</span> = []
174
+ <span class="ruby-identifier">options_list</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">val</span>,<span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
175
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
176
+ <span class="ruby-identifier">val</span> = [<span class="ruby-identifier">val</span>,<span class="ruby-identifier">val</span>]
177
+ <span class="ruby-keyword">end</span>
178
+ <span class="ruby-identifier">key_val</span> = <span class="ruby-identifier">val</span>[<span class="ruby-value">1</span>]
179
+ <span class="ruby-identifier">selected_value_id</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">length</span> <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">selected_value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">selected_value</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">key_val</span>
180
+ <span class="ruby-identifier">new_options_list</span><span class="ruby-operator">&lt;&lt;</span>[<span class="ruby-identifier">val</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">options</span>.<span class="ruby-identifier">length</span>]
181
+ <span class="ruby-identifier">options</span><span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">key_val</span>
182
+ <span class="ruby-keyword">end</span>
183
+ <span class="ruby-identifier">options_list</span> = <span class="ruby-identifier">new_options_list</span>
184
+
185
+ <span class="ruby-identifier">filter</span> = {<span class="ruby-value">:id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">filter_id</span>,<span class="ruby-value">:column_name=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">column_name</span>,<span class="ruby-value">:options=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">options</span>,<span class="ruby-value">:raw_sql=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:raw_sql</span>)}
186
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">add_filter</span> <span class="ruby-identifier">filter</span>
187
+
188
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-filter-key'</span>] = <span class="ruby-identifier">filter_id</span>
189
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-group-id'</span>] = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:group</span>);
190
+ <span class="ruby-identifier">name</span> = <span class="ruby-node">&quot;filters[#{column_name}]&quot;</span>
191
+
192
+
193
+ <span class="ruby-identifier">option_tags</span> = <span class="ruby-identifier">options_for_select</span>(<span class="ruby-identifier">options_list</span>, <span class="ruby-identifier">selected_value</span>) <span class="ruby-comment">#TODO build default list from column maybe ...IE User.all.map{username, id}</span>
194
+ <span class="ruby-identifier">select_tag</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">option_tags</span>, <span class="ruby-identifier">opts</span>)
195
+ <span class="ruby-keyword">end</span></pre>
196
+ </div><!-- sortable_filter_tag-source -->
197
+
198
+ </div>
199
+
200
+
201
+
202
+
203
+ </div><!-- sortable_filter_tag-method -->
204
+
205
+
206
+ <div id="method-i-sortable_table_tag" class="method-detail ">
207
+
208
+ <div class="method-heading">
209
+ <span class="method-name">sortable_table_tag</span><span
210
+ class="method-args">(base_query, columns=[], opts={})</span>
211
+ <span class="method-click-advice">click to toggle source</span>
212
+ </div>
213
+
214
+
215
+ <div class="method-description">
216
+
217
+ <p>table options</p>
218
+
219
+ <pre>- items_per_page
220
+ - disable_backtrace
221
+ - group</pre>
222
+
223
+ <p>col options</p>
224
+
225
+ <pre>- sort_field
226
+ - display_method
227
+ - path_method
228
+ - title
229
+ - no_display
230
+ - td_class
231
+ - link_item
232
+ - disabled</pre>
233
+
234
+
235
+
236
+ <div class="method-source-code" id="sortable_table_tag-source">
237
+ <pre><span class="ruby-comment"># File lib/sortable_skima/helpers/sortable_helper.rb, line 57</span>
238
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">sortable_table_tag</span> <span class="ruby-identifier">base_query</span>, <span class="ruby-identifier">columns</span>=[], <span class="ruby-identifier">opts</span>={}
239
+
240
+ <span class="ruby-identifier">default_opts</span> = {
241
+ <span class="ruby-value">:default_order=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword">nil</span>,
242
+ <span class="ruby-value">:class</span> =<span class="ruby-operator">&gt;</span><span class="ruby-string">'sortable-list'</span>,
243
+ <span class="ruby-value">:items_per_page=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">10</span>,
244
+ <span class="ruby-value">:disable_backtrace=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword">false</span>,
245
+ <span class="ruby-value">:paginate=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword">true</span>,
246
+ <span class="ruby-value">:group=</span><span class="ruby-operator">&gt;</span><span class="ruby-constant">DEFAULT_GROUP</span>
247
+ }
248
+ <span class="ruby-identifier">opts</span> <span class="ruby-operator">||=</span> {}
249
+ <span class="ruby-identifier">default_opts</span>[<span class="ruby-value">:class</span>] = <span class="ruby-node">&quot;#{opts[:class]} #{default_opts[:class]}&quot;</span> <span class="ruby-comment">#any parameter added classes plus 'sortableList'</span>
250
+ <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">default_opts</span>.<span class="ruby-identifier">merge</span> <span class="ruby-identifier">opts</span>
251
+
252
+ <span class="ruby-identifier">do_paginate</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:paginate</span>) <span class="ruby-comment">#opts[:items_per_page]</span>
253
+ <span class="ruby-identifier">disable_backtrace</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:disable_backtrace</span>)
254
+
255
+ <span class="ruby-identifier">srtbl</span> = <span class="ruby-identifier">get_sortable</span> <span class="ruby-identifier">opts</span>
256
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">base_query</span> = <span class="ruby-identifier">base_query</span>
257
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">add_option</span> <span class="ruby-value">:default_order</span>, <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:default_order</span>)
258
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">add_option</span> <span class="ruby-value">:per_page</span>, <span class="ruby-identifier">opts</span>[<span class="ruby-value">:items_per_page</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:items_per_page</span>]
259
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">add_option</span> <span class="ruby-value">:disable_backtrace</span>, <span class="ruby-identifier">disable_backtrace</span>
260
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">add_option</span> <span class="ruby-value">:paginate</span>, <span class="ruby-identifier">do_paginate</span>
261
+
262
+ <span class="ruby-identifier">out</span> = <span class="ruby-string">''</span>
263
+ <span class="ruby-identifier">thead</span> = <span class="ruby-string">''</span>
264
+
265
+ <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">col</span><span class="ruby-operator">|</span>
266
+ <span class="ruby-identifier">sort_field</span> = <span class="ruby-identifier">col</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:sort_field</span>)
267
+ <span class="ruby-identifier">display_method</span> = <span class="ruby-identifier">col</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:display_method</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">sort_field</span>
268
+ <span class="ruby-identifier">col_title</span> = (<span class="ruby-identifier">col</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:title</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">sort_field</span>).<span class="ruby-identifier">html_safe</span>
269
+ <span class="ruby-identifier">path_method</span> = <span class="ruby-identifier">col</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:path_method</span>)
270
+
271
+ <span class="ruby-identifier">col</span>[<span class="ruby-string">'sort-field'</span>] = <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">add_column</span>(<span class="ruby-identifier">sort_field</span>,<span class="ruby-identifier">display_method</span>, <span class="ruby-identifier">path_method</span>)
272
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">col</span>[<span class="ruby-value">:no_display</span>] <span class="ruby-comment">#column is not shown on front table but is still passed to js</span>
273
+ <span class="ruby-identifier">col</span>[<span class="ruby-string">'col-title'</span>]=<span class="ruby-identifier">col_title</span>
274
+ <span class="ruby-identifier">col</span>[<span class="ruby-string">'data-class'</span>]=<span class="ruby-identifier">col</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:td_class</span>)
275
+ <span class="ruby-identifier">col</span>[<span class="ruby-string">'data-link-item'</span>]=<span class="ruby-identifier">col</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:link_item</span>)
276
+ <span class="ruby-identifier">thead</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">content_tag</span>( <span class="ruby-string">'th'</span>, <span class="ruby-identifier">col_title</span>, <span class="ruby-identifier">col</span>).<span class="ruby-identifier">html_safe</span>
277
+ <span class="ruby-keyword">end</span>
278
+ <span class="ruby-keyword">end</span>
279
+
280
+ <span class="ruby-identifier">thead</span> = <span class="ruby-identifier">content_tag</span>(<span class="ruby-string">'thead'</span>,<span class="ruby-identifier">content_tag</span>(<span class="ruby-string">'tr'</span>,<span class="ruby-identifier">thead</span>.<span class="ruby-identifier">html_safe</span>).<span class="ruby-identifier">html_safe</span>)
281
+ <span class="ruby-identifier">tbody</span> = <span class="ruby-identifier">content_tag</span>(<span class="ruby-string">'tbody'</span>,<span class="ruby-string">''</span>)
282
+ <span class="ruby-identifier">out</span> = (<span class="ruby-identifier">thead</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tbody</span>).<span class="ruby-identifier">html_safe</span>
283
+
284
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">save</span>
285
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-sortable-query'</span>] = <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">id</span>
286
+
287
+
288
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-per-page'</span>] = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:items_per_page</span>)
289
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-table-token'</span>] = <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">token</span>
290
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-group-id'</span>] = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:group</span>)
291
+ <span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-initialize-on-client'</span>] = <span class="ruby-identifier">disable_backtrace</span>
292
+
293
+ <span class="ruby-identifier">out</span> = <span class="ruby-identifier">content_tag</span> <span class="ruby-string">'table'</span>, <span class="ruby-identifier">out</span>, <span class="ruby-identifier">opts</span>
294
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">do_paginate</span>
295
+ <span class="ruby-identifier">out</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">content_tag</span> <span class="ruby-string">'div'</span>,<span class="ruby-string">''</span>,<span class="ruby-value">:class</span>=<span class="ruby-operator">&gt;</span><span class="ruby-string">'paginate-container'</span>,<span class="ruby-string">'data-group-id'</span>=<span class="ruby-operator">&gt;</span><span class="ruby-identifier">opts</span>[<span class="ruby-string">'data-group-id'</span>]
296
+ <span class="ruby-keyword">end</span>
297
+ <span class="ruby-identifier">out</span>
298
+ <span class="ruby-keyword">end</span></pre>
299
+ </div><!-- sortable_table_tag-source -->
300
+
301
+ </div>
302
+
303
+
304
+
305
+
306
+ </div><!-- sortable_table_tag-method -->
307
+
308
+
309
+ </section><!-- public-instance-method-details -->
310
+
311
+ <section id="private-instance-5Buntitled-5D-method-details" class="method-section section">
312
+ <h3 class="section-header">Private Instance Methods</h3>
313
+
314
+
315
+ <div id="method-i-get_sortable" class="method-detail ">
316
+
317
+ <div class="method-heading">
318
+ <span class="method-name">get_sortable</span><span
319
+ class="method-args">(opts)</span>
320
+ <span class="method-click-advice">click to toggle source</span>
321
+ </div>
322
+
323
+
324
+ <div class="method-description">
325
+
326
+
327
+
328
+
329
+
330
+ <div class="method-source-code" id="get_sortable-source">
331
+ <pre><span class="ruby-comment"># File lib/sortable_skima/helpers/sortable_helper.rb, line 120</span>
332
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">get_sortable</span> <span class="ruby-identifier">opts</span>
333
+ <span class="ruby-ivar">@sortable_groups</span> <span class="ruby-operator">||=</span> {}
334
+ <span class="ruby-identifier">srtbl</span> = <span class="ruby-ivar">@sortable_groups</span>[<span class="ruby-identifier">opts</span>[<span class="ruby-value">:group</span>]]
335
+ <span class="ruby-keyword">unless</span> <span class="ruby-identifier">srtbl</span>
336
+ <span class="ruby-identifier">srtbl</span> = <span class="ruby-constant">Sortable</span>.<span class="ruby-identifier">new</span>
337
+ <span class="ruby-identifier">srtbl</span>.<span class="ruby-identifier">token</span> = <span class="ruby-node">&quot;#{controller_name}_#{action_name}&quot;</span>
338
+ <span class="ruby-ivar">@sortable_groups</span>[<span class="ruby-identifier">opts</span>[<span class="ruby-value">:group</span>]] = <span class="ruby-identifier">srtbl</span>
339
+ <span class="ruby-keyword">end</span>
340
+ <span class="ruby-identifier">srtbl</span>
341
+ <span class="ruby-keyword">end</span></pre>
342
+ </div><!-- get_sortable-source -->
343
+
344
+ </div>
345
+
346
+
347
+
348
+
349
+ </div><!-- get_sortable-method -->
350
+
351
+
352
+ </section><!-- private-instance-method-details -->
353
+
354
+ </section><!-- 5Buntitled-5D -->
355
+
356
+ </div><!-- documentation -->
357
+
358
+
359
+ <footer id="validator-badges">
360
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
361
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
362
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
363
+ </footer>
364
+