Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 5838 Bytes
1 | <% |
2 | # Render as follows: |
3 | # |
4 | # render( :partial => 'shared/simple_search' ) |
5 | # |
6 | # ...for any model which can be derived from the current controller's name |
7 | # and which defines constant SEARCH_COLUMNS to an array of column names |
8 | # (without locale suffices) listing the columns which are to be searchable. |
9 | # |
10 | # Optionally define local "model" to the model to use (e.g. User), else the |
11 | # value of "controller.controller_name.classify.constantize" is used. |
12 | # |
13 | # If Leightbox is in use, the search partial will hide itself within a |
14 | # Leightbox wrapper and the caller should also render "leightbox_button" to |
15 | # provide access to it. However, the partial is smart; in the event that no |
16 | # results are generated by a given search, hiding the search panel is rather |
17 | # counter-intuitive. Most list views in practice don't render related buttons |
18 | # with empty lists either, so without lots of additional conditional logic in |
19 | # views, this hiding behaviour becomes very unhelpful. Thus the partial will |
20 | # not hide itself inside a Leightbox popup container if a search query exists |
21 | # but no results were found, so the 'errant' search criteria end up shown |
22 | # directly in the page. |
23 | |
24 | if defined?( model ).nil? |
25 | model = controller.controller_name.classify.constantize |
26 | end |
27 | |
28 | trans = model.respond_to?( :columns_for_translation ) |
29 | fields = model::SEARCH_COLUMNS |
30 | first = true |
31 | |
32 | -%> |
33 | <% unless ( @items.empty? && @search_results == false ) -%> |
34 | |
35 | <div id="search_container"> |
36 | <% |
37 | # If QuietLeightbox says 'yes', then in theory we can use a JavaScript |
38 | # based popup by altering the containing DIVs class and ID. Do this change |
39 | # with JavaScript itself, so that non-JS browsers will still use the non-JS |
40 | # version of the markup. |
41 | |
42 | if ( using_quiet_leightbox? ) |
43 | javascript_tag do |
44 | %> |
45 | try |
46 | { |
47 | var divElement = document.getElementById( 'search_container' ); |
48 | <% if ( @items.empty? ) -%> |
49 | divElement.className = 'floaty_clear'; |
50 | <% else -%> |
51 | divElement.className = 'leightbox'; |
52 | divElement.id = 'leightbox_simple_search'; |
53 | <% end -%> |
54 | } |
55 | catch( e ) { /* Ignore */ } |
56 | <% |
57 | end |
58 | end |
59 | %> |
60 | <p /> |
61 | <div class="simple_search round"> |
62 | <h2><%= t( :'uk.org.pond.canvass.search.title' ) %></h2> |
63 | |
64 | <% form_tag ( root_url().chop() + request.path() ), :method => 'get' do %> |
65 | <% if ( controller_name == "messages" && params.has_key?( :sent ) ) -%> |
66 | <%= |
67 | hidden_field_tag( :sent, 'true' ) # Nasty special case; keep "sent" parameter for Sent Messages searches |
68 | %> |
69 | <% end -%> |
70 | <table class="no_border"> |
71 | <% |
72 | fields.each do | field | |
73 | |
74 | # Fields with a "#" inside have a method name to call to generate the |
75 | # form data. |
76 | |
77 | array = field.split( '#' ) |
78 | |
79 | if ( array.size > 1 ) |
80 | field = array.first |
81 | generator_method = array.last |
82 | else |
83 | generator_method = nil |
84 | end |
85 | |
86 | trans_field = trans ? model.translated_column( field ) : field |
87 | entry_id = "s_#{ trans_field }".to_sym |
88 | radio_id = "sr_#{ trans_field }".to_sym |
89 | -%> |
90 | <tr> |
91 | <% |
92 | if ( first == true ) |
93 | first = false |
94 | -%> |
95 | <td align="right" colspan="2"> |
96 | <% else -%> |
97 | <td align="left"> |
98 | <em> |
99 | <%= radio_button_tag( radio_id, :and, params[ radio_id ] != "or" ) %><%= label_tag( "#{ radio_id }_and", t( :'uk.org.pond.canvass.search.and' ) ) %> |
100 | <%= radio_button_tag( radio_id, :or, params[ radio_id ] == "or" ) %><%= label_tag( "#{ radio_id }_or", t( :'uk.org.pond.canvass.search.or' ) ) %> |
101 | </em> |
102 | </td> |
103 | <td align="right"> |
104 | <% end -%> |
105 | <% content_tag :label do %> |
106 | <strong><%= model.human_attribute_name( field ) %></strong> |
107 | <% if ( generator_method.nil? ) -%> |
108 | <%= text_field_tag entry_id, params[ entry_id ] %> |
109 | <% else -%> |
110 | <%= send( generator_method, entry_id, params[ entry_id ] ) %> |
111 | <% end -%> |
112 | <% end %> |
113 | </td> |
114 | </tr> |
115 | <% end -%> |
116 | <tr> |
117 | <td colspan="2" align="right"> |
118 | <div class="buttons"> |
119 | <%= apphelp_submit( nil, t( :'uk.org.pond.canvass.search.start' ), ' ' ) %> |
120 | <%= |
121 | apphelp_protected_button_to( |
122 | :index, |
123 | { |
124 | :url => root_url().chop() + request.path(), |
125 | :text => t( :'uk.org.pond.canvass.search.cancel' ), |
126 | :variant => :negative, |
127 | :bypass => true |
128 | } |
129 | ) |
130 | %> |
131 | </div> |
132 | </td> |
133 | </tr> |
134 | </table> |
135 | <% end %> |
136 | </div> |
137 | <% |
138 | # Only if we are in theory able to use the JavaScript driven popup should a |
139 | # 'close' link be present and write this itself with JavaScript, so non-JS |
140 | # browsers fall back to showing nothing here - the desired result as the |
141 | # search panel will be rendered inline in those cases (see earlier). |
142 | # |
143 | # The inline script deliberately uses DOM methods rather than something as |
144 | # simple as 'document.write', to try and make sure that the level of JS |
145 | # support, if there is any, is sufficient. |
146 | |
147 | if ( using_quiet_leightbox? && ! @items.empty? ) |
148 | javascript_tag do |
149 | -%> |
150 | try |
151 | { |
152 | var aElement = document.createElement( 'a' ); |
153 | aElement.href = '#'; |
154 | aElement.className = 'lbAction'; |
155 | aElement.rel = 'deactivate'; |
156 | aElement.innerHTML = "<%= json_escape( t( :'uk.org.pond.canvass.search.close' ) ).gsub( '"', '\"' ) %>"; |
157 | |
158 | divElement.appendChild( aElement ); |
159 | } |
160 | catch( e ) { /* Ignore */ } |
161 | <% |
162 | end |
163 | end |
164 | -%> |
165 | </div> |
166 | <% end -%> |