poll_js

NAML documentation   Watch a video
   Usages of this macro
... in poll_js.naml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<override_macro name="poll_js" requires="servlet">
    <n.comment
Macro
Parameters: text
.>
        This is the javascript code that will update the poll controls and make them available to the users.
    </n.comment.>
    <n.param_loop
Macro
Parameters: param, do
. param="poll_node_id">
        <n.get_node_from_id
Binary
Namespace: NabbleNamespace
Parameters: do, node_id
. node_id="[n.current_parameter_value
Binary
Namespace: ParameterValueList
/]">
            <n.set_local_node
Macro
Parameters: node
.this_node
Binary
Namespace: NodeNamespace
Parameters: do
 />
            <n.if
Binary
Namespace: BasicNamespace
Parameters: condition, else, then
.visitor
Binary
Namespace: ServletNamespace
Parameters: do
.is_registered
Binary
Namespace: UserNamespace
>
                <then>
                    <n.poll_option_list
Binary
Namespace: NodeNamespaceExt
Parameters: do
.loop
Macro
Requires: sequence
Parameters: by, do
.>
                        var input = '<n.local_node
Macro
Parameters: do
.poll_vote_input_field
Macro
Requires: node
Parameters: field_id, index
 field_id="option[n.option_id
Binary
Namespace: PollOptionList
/]" index="[n.current_index
Binary
Namespace: ListSequence
/]"/>';
                        $('#poll-option-input<n.option_id
Binary
Namespace: PollOptionList
/>').html(input);
                    </n.poll_option_list.loop.>
 
                    <n.if
Binary
Namespace: BasicNamespace
Parameters: condition, else, then
.poll_has_ended
Binary
Namespace: NodeNamespaceExt
Parameters: do
>
                        <then>
                            var input = '<t>This poll is closed.</t>';
                        </then>
                        <else>
                            var txt_vote = "<t>Vote</t>";
                            var input = '<input type="submit" value="' + txt_vote + '"/>';
                            if (!<n.visitor
Binary
Namespace: ServletNamespace
Parameters: do
.can_create_poll_in
Macro
Requires: user
Parameters: node_attr
.page_node
Macro
Requires: parameter_value_list
Parameters: do
/>)
                                input = '<input type="submit" value="' + txt_vote + '" disabled="true"/>';
                        </else>
                    </n.if.poll_has_ended>
                    $('#poll-submit-button<n.id
Binary
Namespace: NodeNamespace
/>').html(input);
                </then>
            </n.if.visitor.is_registered>
 
            <n.if
Binary
Namespace: BasicNamespace
Parameters: condition, else, then
.poll_visitor_can_see_votes
Binary
Namespace: NodeNamespaceExt
Parameters: do
>
                <then>
                    var total_votes = 0;
                    <n.poll_vote_counts
Binary
Namespace: NodeNamespaceExt
Parameters: do
.loop
Macro
Requires: sequence
Parameters: by, do
.>
                        var text = <n.current_string
Binary
Namespace: StringList
/> == 1? '(<t>1 vote</t>)' : '(<t><t.number.current_string
Binary
Namespace: StringList
/> votes</t>)';
                        $('#poll-vote-count<n.option_id
Binary
Namespace: PollOptionList
/>').html(text);
                        total_votes += <n.current_string
Binary
Namespace: StringList
/>;
                    </n.poll_vote_counts.loop.>
                    var text = '<t>Total votes:</t> ' + total_votes;
                    $('#poll-total-votes<n.local_node
Macro
Parameters: do
.id
Binary
Namespace: NodeNamespace
/>').html(text).show();
                </then>
            </n.if.poll_visitor_can_see_votes>
        </n.get_node_from_id.>
    </n.param_loop.>
</override_macro>
Overrides default macro
... in poll.naml
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<macro name="poll_js" requires="servlet">
    <n.comment.>
        This is the javascript code that will update the poll controls and make them available to the users.
    </n.comment.>
    <n.param_loop. param="poll_node_id">
        <n.get_node_from_id. node_id="[n.current_parameter_value/]">
            <n.set_local_node.this_node />
            <n.if.visitor.is_registered>
                <then>
                    <n.poll_option_list.loop.>
                        var input = '<n.local_node.poll_vote_input_field field_id="option[n.option_id/]" index="[n.current_index/]"/>';
                        $('#poll-option-input<n.option_id/>').html(input);
                    </n.poll_option_list.loop.>
 
                    <n.if.poll_has_ended>
                        <then>
                            var input = '<t>This poll is closed.</t>';
                        </then>
                        <else>
                            var txt_vote = "<t>Vote</t>";
                            var input = '<input type="submit" value="' + txt_vote + '"/>';
                            if (!<n.poll_visitor_can_vote/>)
                                input = '<input type="submit" value="' + txt_vote + '" disabled="true"/>';
                        </else>
                    </n.if.poll_has_ended>
                    $('#poll-submit-button<n.id/>').html(input);
                </then>
            </n.if.visitor.is_registered>
 
            <n.if.poll_visitor_can_see_votes>
                <then>
                    var total_votes = 0;
                    <n.poll_vote_counts.loop.>
                        var text = <n.current_string/> == 1? '(<t>1 vote</t>)' : '(<t><t.number.current_string/> votes</t>)';
                        $('#poll-vote-count<n.option_id/>').html(text);
                        total_votes += <n.current_string/>;
                    </n.poll_vote_counts.loop.>
                    var text = '<t>Total votes:</t> ' + total_votes;
                    $('#poll-total-votes<n.local_node.id/>').html(text).show();
                </then>
            </n.if.poll_visitor_can_see_votes>
        </n.get_node_from_id.>
    </n.param_loop.>
</macro>