Commits

Puria Nafisi Azizi committed 3bbae00

Fancying with jquery stuff like animating

Comments (0)

Files changed (1)

tgpolls/templates/poll_partial.html

             <input type="checkbox" name="${poll.uid}" value="${answer.uid}">
                 ${answer.text}
             </input>
-            Votes: ${answer.votes or '0'}
+            Votes: <span>${answer.votes or '0'}</span>
         </li>
     </ul>
-    <a href="#" id="vote_for_poll_${poll.uid}" class="btn btn-primary">VOTE</a>
+    <a href="#" id="vote_for_poll_${poll.uid}" class="btn btn-primary ${'disabled' if 'poll_%s' % poll.uid in tg.session else ''}">VOTE</a>
     <script>
         jQuery('#vote_for_poll_${poll.uid}').click(function() {
+            if (jQuery(this).hasClass('disabled')) return false;
             var votes = jQuery.map($('input:checkbox:checked[name=${poll.uid}]'), function(e,i) {
+                var vote = jQuery(e).siblings('span');
+                vote.html(parseInt(vote.html()) + 1);
                 return +e.value;
             });
-
             jQuery.get("${h.plug_url('tgpolls', '/vote')}", { poll_uid: "${poll.uid}", votes: votes });
+            jQuery(this).addClass('disabled');
         });
     </script>