0
|
1 === Permission ===
|
|
2
|
|
3 <macro name="create_poll_permission">
|
|
4 Create_poll
|
|
5 </macro>
|
|
6
|
|
7 <macro name="can_create_poll_in" requires="user" dot_parameter="node_attr">
|
|
8 <n.set_local_user.this_user />
|
|
9 <n.set_local_node.node_attr/>
|
|
10 <n.both>
|
|
11 <condition1.local_user.is_registered/>
|
|
12 <condition2.either>
|
|
13 <condition1.local_user.is_site_admin/>
|
|
14 <condition2.local_user.has_permission node="[n.local_node/]" permission_node="[n.local_node.app_or_root/]" permission="[n.create_poll_permission/]" />
|
|
15 </condition2.either>
|
|
16 </n.both>
|
|
17 </macro>
|
|
18
|
|
19 <override_macro name="all_permissions_list">
|
|
20 <n.overridden />
|
|
21 <n.create_poll_permission/>,
|
|
22 </override_macro>
|
|
23
|
|
24 <override_macro name="permission_rows">
|
|
25 <n.overridden />
|
|
26 <n.permission_row
|
|
27 permission = "[n.create_poll_permission/]"
|
|
28 description="[t]Who can create polls.[/t]"
|
|
29 administrators_cell = "true"
|
|
30 />
|
|
31 </override_macro>
|
|
32
|
|
33 === Node Message ===
|
|
34
|
|
35 <override_macro name="node_message_as_html" requires="node">
|
|
36 <n.overridden />
|
|
37
|
|
38 <n.comment.>
|
|
39 If this is a topic page (which calls the "message_text" command), then show the poll.
|
|
40 Otherwise (email messages), print a link to the poll.
|
|
41 </n.comment.>
|
|
42 <n.if.is_in_command name="email_message">
|
|
43 <then.poll_link/>
|
|
44 <else.poll/>
|
|
45 </n.if.is_in_command>
|
|
46 </override_macro>
|
|
47
|
|
48 <macro name="poll_link" requires="node">
|
|
49 <n.if.has_poll>
|
|
50 <then>
|
|
51 <div style="background-color:#FFFADB;border:#EDDD79 solid 1px;margin-top:1em;padding:.5em">
|
|
52 <b><t>This message has a poll</t></b> -- <t>Visit the link below if you want to participate:</t><br/>
|
|
53 <a href="[n.url/]"><n.url/></a>
|
|
54 </div>
|
|
55 </then>
|
|
56 </n.if.has_poll>
|
|
57 </macro>
|
|
58
|
|
59 <override_macro name="message_as_text" requires="message" unindent="true">
|
|
60 <n.overridden/>
|
|
61
|
|
62 <n.if.is_in_command name="node_message_block">
|
|
63 <then.if.message_block_node.has_poll>
|
|
64 <then>
|
|
65 <n.crlf/>[<t>Poll</t>] <t>This message has a poll</t> / <t>Visit the link below if you want to participate:</t>
|
|
66 <n.message_block_node.url/>
|
|
67 </then>
|
|
68 </then.if.message_block_node.has_poll>
|
|
69 </n.if.is_in_command >
|
|
70 </override_macro>
|
|
71
|
|
72 === New post page ===
|
|
73
|
|
74 <override_macro name="new_post_extra_fields" requires="node_page">
|
|
75 <n.overridden/>
|
|
76
|
|
77 <n.if.both condition1="[n.page_node.is_app/]" condition2="[n.visitor.can_create_poll_in.page_node/]">
|
|
78 <then>
|
|
79 <div class="extra-fields">
|
|
80 <img src="/images/add.png" width="12" height="12" style="margin-top:.2em"/>
|
|
81 <n.add_poll_form/>
|
|
82 </div>
|
|
83 </then>
|
|
84 </n.if.both>
|
|
85 </override_macro>
|
|
86
|
|
87 <override_macro name="init_new_post_custom_fields">
|
|
88 <n.overridden/>
|
|
89 <n.if.visitor.can_create_poll_in.page_node>
|
|
90 <then>
|
|
91 <n.poll_max_choices_field.set_value value="1" />
|
|
92 <n.poll_allow_vote_change_field.set_value value="true" />
|
|
93 <n.poll_show_results_before_vote_field.set_value value="true" />
|
|
94 <n.poll_show_results_before_end_field.set_value value="true" />
|
|
95 </then>
|
|
96 </n.if.visitor.can_create_poll_in.page_node>
|
|
97 </override_macro>
|
|
98
|
|
99 <override_macro name="save_new_post_custom_fields">
|
|
100 <n.overridden/>
|
|
101 <n.if.visitor.can_create_poll_in.page_node>
|
|
102 <then.new_node.save_new_poll/>
|
|
103 </n.if.visitor.can_create_poll_in.page_node>
|
|
104 </override_macro>
|
|
105
|
|
106 === Edit post page ===
|
|
107
|
|
108 <override_macro name="edit_post_extra_fields" requires="node_page">
|
|
109 <n.overridden/>
|
|
110
|
|
111 <n.if.both condition1="[n.page_node.parent_node.is_app/]" condition2="[n.visitor.can_create_poll_in.page_node/]">
|
|
112 <then>
|
|
113 <div class="extra-fields">
|
|
114 <img src="/images/add.png" width="12" height="12" style="margin-top:.2em"/>
|
|
115 <n.if.page_node.has_poll>
|
|
116 <then.edit_poll_form/>
|
|
117 <else.add_poll_form/>
|
|
118 </n.if.page_node.has_poll>
|
|
119 </div>
|
|
120 </then>
|
|
121 </n.if.both>
|
|
122 </override_macro>
|
|
123
|
|
124 <override_macro name="init_edit_post_custom_fields" requires="node_page">
|
|
125 <n.overridden/>
|
|
126 <n.if.both condition1="[n.page_node.has_poll/]" condition2="[n.visitor.can_create_poll_in.page_node/]">
|
|
127 <then>
|
|
128 <n.poll_max_choices_field.set_value value="[n.page_node.poll_max_choices/]" />
|
|
129 <n.poll_days_left_field.set_value value="[n.page_node.poll_days_left/]" />
|
|
130 <n.poll_allow_vote_change_field.set_value value="[n.page_node.poll_allow_vote_change/]" />
|
|
131 <n.poll_show_results_before_vote_field.set_value value="[n.page_node.poll_show_results_before_vote/]" />
|
|
132 <n.poll_show_results_before_end_field.set_value value="[n.page_node.poll_show_results_before_end/]" />
|
|
133 </then>
|
|
134 </n.if.both>
|
|
135 </override_macro>
|
|
136
|
|
137 <override_macro name="save_edit_post_custom_fields" requires="node_page">
|
|
138 <n.overridden/>
|
|
139 <n.if.both condition1="[n.page_node.has_poll/]" condition2="[n.visitor.can_create_poll_in.page_node/]">
|
|
140 <then>
|
|
141 <n.edit_poll>
|
|
142 <poll_max_choices>
|
|
143 <n.get_int. default="1" exception="max_choices_field_not_integer"><n.poll_max_choices_field.value/></n.get_int.>
|
|
144 </poll_max_choices>
|
|
145 <poll_days_left><n.to_null_if. equals=""><n.poll_days_left_field.value/></n.to_null_if.></poll_days_left>
|
|
146 <poll_allow_vote_change><n.poll_allow_vote_change_field.value/></poll_allow_vote_change>
|
|
147 <poll_show_results_before_vote><n.poll_show_results_before_vote_field.value/></poll_show_results_before_vote>
|
|
148 <poll_show_results_before_end><n.poll_show_results_before_end_field.value/></poll_show_results_before_end>
|
|
149 </n.edit_poll>
|
|
150 </then>
|
|
151 <else.page_node.save_new_poll/>
|
|
152 </n.if.both>
|
|
153 </override_macro>
|
|
154
|
|
155 === Error Handling ===
|
|
156
|
|
157 <override_macro name="custom_new_node_errors">
|
|
158 <n.overridden/>
|
|
159 <n.poll_errors/>
|
|
160 </override_macro>
|
|
161
|
|
162 <override_macro name="custom_edit_post_errors">
|
|
163 <n.overridden/>
|
|
164 <n.poll_errors/>
|
|
165 </override_macro>
|
|
166
|
|
167 <macro name="poll_errors" requires="error">
|
|
168 <n.exception. name="invalid_poll_format">
|
|
169 <t>Invalid poll parameters.</t>
|
|
170 </n.exception.>
|
|
171 <n.exception. name="days_field_not_integer">
|
|
172 <t>Poll duration must be a non-negative integer or blank.</t>
|
|
173 </n.exception.>
|
|
174 <n.exception. name="max_choices_field_not_integer">
|
|
175 <t>Poll maximum allowed choices must be a non-negative integer or blank.</t>
|
|
176 </n.exception.>
|
|
177 </macro>
|
|
178
|
|
179 === Javascript Handler ===
|
|
180
|
|
181 <override_macro name="extra_call_later_handlers">
|
|
182 <n.overridden/>
|
|
183 <n.poll_js/>
|
|
184 </override_macro>
|
|
185
|
|
186 === Other macros ===
|
|
187
|
|
188 <macro name="add_poll_form" requires="node_page">
|
|
189 <script type="text/javascript">
|
|
190 function addPoll() {
|
|
191 $('#poll').show();
|
|
192 if ( $('#poll-options div').size() == 0 ) {
|
|
193 addOption(false);
|
|
194 addOption(false);
|
|
195 } else
|
|
196 updateOptions();
|
|
197 Nabble.resizeFrames();
|
|
198 };
|
|
199 function removeOption(e) {
|
|
200 $(e).parent().remove();
|
|
201 updateOptions();
|
|
202 Nabble.resizeFrames();
|
|
203 };
|
|
204 function addOption(focus) {
|
|
205 $('#poll-options').append('<n.javascript_string_encode.poll_option_input_row/>');
|
|
206 updateOptions();
|
|
207 if (focus)
|
|
208 $('#poll-options div input').last().focus();
|
|
209 Nabble.resizeFrames();
|
|
210 };
|
|
211 function updateOptions() {
|
|
212 var c = 1;
|
|
213 $('#poll-options div').each(function() {
|
|
214 $('a,span', this).remove();
|
|
215 $(this).prepend('<span>'+c+'.</span>');
|
|
216 if (c++ > 2) {
|
|
217 $(this).append('<a class="removeOption" href="javascript:void(0)" onclick="removeOption(this)"><t>remove</t></a>');
|
|
218 }
|
|
219 });
|
|
220 };
|
|
221 function removePoll() {
|
|
222 $('input[name=poll_question]').val('');
|
|
223 $('#poll').hide();
|
|
224 };
|
|
225 <n.if.not.is_empty.poll_question_field.value>
|
|
226 <then>
|
|
227 $(document).ready(function() {
|
|
228 updateOptions();
|
|
229 });
|
|
230 </then>
|
|
231 </n.if.not.is_empty.poll_question_field.value>
|
|
232 </script>
|
|
233 <a href="javascript: void(0)" onclick="addPoll()"><t>Add new poll</t></a>
|
|
234
|
|
235 <div id="poll" class="extra-field-details medium-border-color" style="[n.if.is_empty.poll_question_field.value][then]display:none[/then][/n.if.is_empty.poll_question_field.value]">
|
|
236 <table>
|
|
237 <tr valign="top">
|
|
238 <td style="text-align:right;padding-top:.4em"><t>Question:</t></td>
|
|
239 <td style="padding-left:1.8em"><n.poll_question_field.input type="text" size="40"/></td>
|
|
240 </tr>
|
|
241 <tr valign="top">
|
|
242 <td style="text-align:right;padding-top:.4em"><t>Answers:</t></td>
|
|
243 <td style="padding-left:.7em">
|
|
244 <div id="poll-options" style="padding-bottom:.3em">
|
|
245 <n.get_parameter_values. name="poll_option">
|
|
246 <n.loop.poll_option_input_row.current_parameter_value/>
|
|
247 </n.get_parameter_values.>
|
|
248 </div>
|
|
249 <a href="javascript: void addOption(true)"><t>Add new answer</t></a>
|
|
250 </td>
|
|
251 </tr>
|
|
252 </table>
|
|
253 <n.poll_settings/>
|
|
254 <a href="javascript: void(0)" onclick="removePoll()"><t>Remove Poll</t></a>
|
|
255 </div>
|
|
256 </macro>
|
|
257
|
|
258 <macro name="edit_poll_form" requires="node_page">
|
|
259 <script type="text/javascript">
|
|
260 Nabble.deletePoll = function(nodeId) {
|
|
261 var call = '/template/NamlServlet.jtp?macro=delete_poll_js&node='+nodeId;
|
|
262 if (confirm("<t>Delete this poll, including all votes?</t>")) {
|
|
263 $.getScript(call, function() {
|
|
264 notice('<t>Poll has been deleted.</t>', 2000, 2000);
|
|
265 $('#poll').remove();
|
|
266 });
|
|
267 }
|
|
268 return false;
|
|
269 };
|
|
270 </script>
|
|
271 <n.page_node.>
|
|
272 <t>Poll</t>
|
|
273
|
|
274 <div id="poll" class="extra-field-details medium-border-color">
|
|
275 <div class="weak-color" style="padding:.3em">
|
|
276 <div class="bold"><n.encode.poll_question/></div>
|
|
277 <ul style="margin:.3em 0">
|
|
278 <n.poll_option_list.loop.>
|
|
279 <li><n.current_string/></li>
|
|
280 </n.poll_option_list.loop.>
|
|
281 </ul>
|
|
282 <n.poll_settings />
|
|
283 <a href="javascript: void(0)" onclick="Nabble.deletePoll([n.id/])"><t>Remove Poll</t></a>
|
|
284 </div>
|
|
285 </div>
|
|
286 </n.page_node.>
|
|
287 </macro>
|
|
288
|
|
289 <macro name="poll_settings">
|
|
290 <div style="margin: .5em 0 .5em 1em">
|
|
291 <t>Multiple selections allowed:</t> <n.poll_max_choices_field.input type="text" size="2" maxlength="2"/><br />
|
|
292 <t>Poll ends after <t.number.poll_days_left_field.input type="text" size="2" maxlength="3"/> days (leave blank for unlimited).</t><br />
|
|
293 <n.poll_allow_vote_change_field.checkbox/> <label for="poll_allow_vote_change"><t>Allow vote changes</t></label><br />
|
|
294 <n.poll_show_results_before_vote_field.checkbox/> <label for="poll_show_results_before_vote"><t>Allow viewing results before vote</t></label><br />
|
|
295 <n.poll_show_results_before_end_field.checkbox/> <label for="poll_show_results_before_end"><t>Allow viewing results before end date (poll creators can always view the results)</t></label>
|
|
296 </div>
|
|
297 </macro>
|
|
298
|
|
299 <macro name="save_new_poll" requires="node">
|
|
300 <n.if.not.is_empty.poll_question_field.value>
|
|
301 <then>
|
|
302 <n.set_poll>
|
|
303 <poll_question><n.poll_question_field.value/></poll_question>
|
|
304 <poll_options><n.get_parameter_values name="poll_option"/></poll_options>
|
|
305 <poll_max_choices>
|
|
306 <n.get_int. default="1" exception="max_choices_field_not_integer"><n.poll_max_choices_field.value/></n.get_int.>
|
|
307 </poll_max_choices>
|
|
308 <poll_days_left>
|
|
309 <n.get_int. default="0" exception="days_field_not_integer"><n.poll_days_left_field.value/></n.get_int.>
|
|
310 </poll_days_left>
|
|
311 <poll_allow_vote_change><n.poll_allow_vote_change_field.value/></poll_allow_vote_change>
|
|
312 <poll_show_results_before_vote><n.poll_show_results_before_vote_field.value/></poll_show_results_before_vote>
|
|
313 <poll_show_results_before_end><n.poll_show_results_before_end_field.value/></poll_show_results_before_end>
|
|
314 </n.set_poll>
|
|
315 </then>
|
|
316 </n.if.not.is_empty.poll_question_field.value>
|
|
317 </macro>
|
|
318
|
|
319 <macro name="poll_question_field" dot_parameter="do">
|
|
320 <n.field. name="poll_question"><n.do/></n.field.>
|
|
321 </macro>
|
|
322
|
|
323 <macro name="poll_max_choices_field" dot_parameter="do">
|
|
324 <n.field. name="poll_max_choices"><n.do/></n.field.>
|
|
325 </macro>
|
|
326
|
|
327 <macro name="poll_days_left_field" dot_parameter="do">
|
|
328 <n.field. name="poll_days_left"><n.do/></n.field.>
|
|
329 </macro>
|
|
330
|
|
331 <macro name="poll_allow_vote_change_field" dot_parameter="do">
|
|
332 <n.field. name="poll_allow_vote_change"><n.do/></n.field.>
|
|
333 </macro>
|
|
334
|
|
335 <macro name="poll_show_results_before_vote_field" dot_parameter="do">
|
|
336 <n.field. name="poll_show_results_before_vote"><n.do/></n.field.>
|
|
337 </macro>
|
|
338
|
|
339 <macro name="poll_show_results_before_end_field" dot_parameter="do">
|
|
340 <n.field. name="poll_show_results_before_end"><n.do/></n.field.>
|
|
341 </macro>
|
|
342
|
|
343 <macro name="poll_option_input_row" dot_parameter="poll_option">
|
|
344 <div class="nowrap">
|
|
345 <input type="text" class="poll_option" name="poll_option" size="30" value="[n.hide_null.poll_option/]" />
|
|
346 </div>
|
|
347 </macro>
|
|
348
|
|
349 <macro name="delete_poll_js">
|
|
350 <n.get_node_from_id. node_id="[n.get_parameter name='node'/]">
|
|
351 <n.delete_poll />
|
|
352 </n.get_node_from_id.>
|
|
353 </macro>
|
|
354
|
|
355 <macro name="poll" requires="node">
|
|
356 <n.comment.>
|
|
357 Builds the poll interface. Since some options depend on the current visitor, we use javascript
|
|
358 to set up some fields. Please look at the "poll_js" macro in order to understand how this poll UI is updated.
|
|
359 </n.comment.>
|
|
360 <n.if.has_poll>
|
|
361 <then>
|
|
362 <form method="POST" id="poll_form[n.id/]" onsubmit="return Nabble.vote([n.id/],[n.poll_max_choices/]);" accept-charset="UTF-8" >
|
|
363 <input type="hidden" name="node" value="[n.id/]" />
|
|
364
|
|
365 <div class="medium-border-color border2 rounded" style="margin-top:1em;padding:1em">
|
|
366 <div class="big-title second-font">
|
|
367 <n.encode.poll_question/>
|
|
368 </div>
|
|
369 <n.explain_poll_max_choices/>
|
|
370
|
|
371 <n.poll_option_list.loop.>
|
|
372 <div style="margin:.4em 0 0 1em">
|
|
373 <span id="poll-option-input[n.option_id/]"></span>
|
|
374 <label for="option[n.option_id/]"><n.encode.current_string/></label>
|
|
375 <span id="poll-vote-count[n.option_id/]" class="weak-color" style="font-size:80%"></span>
|
|
376 </div>
|
|
377 </n.poll_option_list.loop.>
|
|
378
|
|
379 <div style="margin-top:.7em">
|
|
380 <n.poll_submit_button/>
|
|
381
|
|
382 <n.poll_total_votes/>
|
|
383 </div>
|
|
384 <n.poll_description_lines/>
|
|
385 </div>
|
|
386 </form>
|
|
387 <n.call_later value="[n.id/]" param="poll_node_id"/>
|
|
388 </then>
|
|
389 </n.if.has_poll>
|
|
390 </macro>
|
|
391
|
|
392 <macro name="poll_js" requires="servlet">
|
|
393 <n.comment.>
|
|
394 This is the javascript code that will update the poll controls and make them available to the users.
|
|
395 </n.comment.>
|
|
396 <n.param_loop. param="poll_node_id">
|
|
397 <n.get_node_from_id. node_id="[n.current_parameter_value/]">
|
|
398 <n.set_local_node.this_node />
|
|
399 <n.if.visitor.is_registered>
|
|
400 <then>
|
|
401 <n.poll_option_list.loop.>
|
|
402 var input = '<n.local_node.poll_vote_input_field field_id="option[n.option_id/]" index="[n.current_index/]"/>';
|
|
403 $('#poll-option-input<n.option_id/>').html(input);
|
|
404 </n.poll_option_list.loop.>
|
|
405
|
|
406 <n.if.poll_has_ended>
|
|
407 <then>
|
|
408 var input = '<t>This poll is closed.</t>';
|
|
409 </then>
|
|
410 <else>
|
|
411 var txt_vote = "<t>Vote</t>";
|
|
412 var input = '<input type="submit" value="' + txt_vote + '"/>';
|
|
413 if (!<n.poll_visitor_can_vote/>)
|
|
414 input = '<input type="submit" value="' + txt_vote + '" disabled="true"/>';
|
|
415 </else>
|
|
416 </n.if.poll_has_ended>
|
|
417 $('#poll-submit-button<n.id/>').html(input);
|
|
418 </then>
|
|
419 </n.if.visitor.is_registered>
|
|
420
|
|
421 <n.if.poll_visitor_can_see_votes>
|
|
422 <then>
|
|
423 var total_votes = 0;
|
|
424 <n.poll_vote_counts.loop.>
|
|
425 var text = <n.current_string/> == 1? '(<t>1 vote</t>)' : '(<t><t.number.current_string/> votes</t>)';
|
|
426 $('#poll-vote-count<n.option_id/>').html(text);
|
|
427 total_votes += <n.current_string/>;
|
|
428 </n.poll_vote_counts.loop.>
|
|
429 var text = '<t>Total votes:</t> ' + total_votes;
|
|
430 $('#poll-total-votes<n.local_node.id/>').html(text).show();
|
|
431 </then>
|
|
432 </n.if.poll_visitor_can_see_votes>
|
|
433 </n.get_node_from_id.>
|
|
434 </n.param_loop.>
|
|
435 </macro>
|
|
436
|
|
437 <macro name="poll_submit_button" requires="node">
|
|
438 <n.comment.>
|
|
439 Creates the submit button. Initially, it is just a span with some default text.
|
|
440 The content of the span is updated by javascript code (see "poll_js" macro for more info)
|
|
441 </n.comment.>
|
|
442 <span id="poll-submit-button[n.id/]" class="bold">
|
|
443 <n.if.poll_has_ended>
|
|
444 <then><t>This poll is closed.</t></then>
|
|
445 <else>
|
|
446 <n.login_link.><t>Login to vote</t></n.login_link.>
|
|
447 </else>
|
|
448 </n.if.poll_has_ended>
|
|
449 </span>
|
|
450 </macro>
|
|
451
|
|
452 <macro name="poll_total_votes" requires="node">
|
|
453 <n.comment.>
|
|
454 The span below shows the total number of votes.
|
|
455 This element is updated by javascript code (see "poll_js" macro for more info)
|
|
456 </n.comment.>
|
|
457 <span id="poll-total-votes[n.id/]" class="shaded-bg-color rounded" style="padding:.2em .4em;display:none"></span>
|
|
458 </macro>
|
|
459
|
|
460 <macro name="poll_description_lines">
|
|
461 <div class="weak-color" style="font-size:80%;margin-top:.6em">
|
|
462 <n.if.not.poll_allow_vote_change>
|
|
463 <then>
|
|
464 <t>You cannot change your vote after voting.</t><br/>
|
|
465 </then>
|
|
466 </n.if.not.poll_allow_vote_change>
|
|
467 <n.if.poll_has_end_date>
|
|
468 <then>
|
|
469 <n.if.poll_has_ended>
|
|
470 <then>
|
|
471 <t>This poll ended on <t.date.poll_end_date.long_format/>.</t><br/>
|
|
472 </then>
|
|
473 <else>
|
|
474 <t>This poll ends on <t.date.poll_end_date.long_format/>.</t><br/>
|
|
475 <n.if.not.poll_show_results_before_end>
|
|
476 <then>
|
|
477 <t>Results will be shown only after poll has ended.</t><br/>
|
|
478 </then>
|
|
479 </n.if.not.poll_show_results_before_end>
|
|
480 </else>
|
|
481 </n.if.poll_has_ended>
|
|
482 </then>
|
|
483 </n.if.poll_has_end_date>
|
|
484 <n.if.not.poll_show_results_before_vote>
|
|
485 <then>
|
|
486 <t>You have to vote before you can see the results.</t><br/>
|
|
487 </then>
|
|
488 </n.if.not.poll_show_results_before_vote>
|
|
489 </div>
|
|
490 </macro>
|
|
491
|
|
492 <macro name="explain_poll_max_choices">
|
|
493 <n.if.not.equal value1="[n.poll_max_choices/]" value2="1">
|
|
494 <then>
|
|
495 <div class="weak-color" style="font-size:80%">
|
|
496 <t>You can select up to <t.number.poll_max_choices/> options.</t>
|
|
497 </div>
|
|
498 </then>
|
|
499 </n.if.not.equal>
|
|
500 </macro>
|
|
501
|
|
502 <macro name="vote_input_type" requires="node">
|
|
503 <n.if.equal value1="[n.poll_max_choices/]" value2="1">
|
|
504 <then>radio</then>
|
|
505 <else>checkbox</else>
|
|
506 </n.if.equal>
|
|
507 </macro>
|
|
508
|
|
509 <macro name="poll_vote_input_field" parameters="field_id, index" requires="node">
|
|
510 <n.comment.>
|
|
511 Creates an input field for a poll option. There are some possibilities
|
|
512 depending on the poll configuration and who is the visitor.
|
|
513 </n.comment.>
|
|
514 <n.if.poll_visitor_has_voted.index>
|
|
515 <then>
|
|
516 <n.if.poll_visitor_can_vote>
|
|
517 <then>
|
|
518 <input id="[n.field_id/]" type="[n.vote_input_type/]" name="vote" value="[n.index/]" checked="true" />
|
|
519 </then>
|
|
520 <else>
|
|
521 <input id="[n.field_id/]" type="[n.vote_input_type/]" name="vote" value="[n.index/]" checked="true" disabled="true" />
|
|
522 </else>
|
|
523 </n.if.poll_visitor_can_vote>
|
|
524 </then>
|
|
525 <else>
|
|
526 <n.if.poll_visitor_can_vote>
|
|
527 <then>
|
|
528 <input id="[n.field_id/]" type="[n.vote_input_type/]" name="vote" value="[n.index/]"/>
|
|
529 </then>
|
|
530 <else>
|
|
531 <input id="[n.field_id/]" type="[n.vote_input_type/]" name="vote" value="[n.index/]" disabled="true" />
|
|
532 </else>
|
|
533 </n.if.poll_visitor_can_vote>
|
|
534 </else>
|
|
535 </n.if.poll_visitor_has_voted.index>
|
|
536 </macro>
|
|
537
|
|
538 <override_macro name="javascript_library" requires="servlet">
|
|
539 <n.overridden/>
|
|
540 <n.comment.>
|
|
541 Javascript to validate and submit a poll vote.
|
|
542 </n.comment.>
|
|
543 <n.compress.>
|
|
544 Nabble.vote = function(nodeId,maxChoices) {
|
|
545 var vote_count = $('#poll_form'+nodeId+' input:checked').length;
|
|
546 <![CDATA[
|
|
547 if (vote_count > maxChoices) {
|
|
548 ]]>
|
|
549 alert('<t>Please select no more than <t.number>'+maxChoices+'</t.number> options.</t>');
|
|
550 return false;
|
|
551 } else if (vote_count == 0) {
|
|
552 alert('<t>Please select at least one option.</t>');
|
|
553 return false;
|
|
554 }
|
|
555 var params = $('#poll_form'+nodeId).serialize();
|
|
556 var call = '/template/NamlServlet.jtp?macro=vote&'+params;
|
|
557 var call2 = '/template/NamlServlet.jtp?macro=poll_js&poll_node_id='+nodeId;
|
|
558 $.getScript(call, function() {
|
|
559 notice('<t>Your vote has been submitted.</t>', 5000, 2000);
|
|
560 $.getScript(call2);
|
|
561 });
|
|
562 return false;
|
|
563 };
|
|
564 </n.compress.>
|
|
565 </override_macro>
|
|
566
|
|
567 <macro name="vote">
|
|
568 <n.get_node_from_id. node_id="[n.get_parameter name='node'/]">
|
|
569 <n.poll_vote votes="[n.get_parameter_values name='vote'/]" />
|
|
570 </n.get_node_from_id.>
|
|
571 </macro> |