Permalink
Browse files

automatic reordering

  • Loading branch information...
yanick committed Mar 27, 2012
1 parent 1df3ec0 commit 5d0d261e433d6ef169d2fa44c0d152908057c144
Showing with 37 additions and 0 deletions.
  1. +37 −0 root/templates/entries/index.html
@@ -86,11 +86,45 @@ <h2>Voting Rules</h2>
decimal: false,
negative: false
});
+
+ $('.title-vote').blur(function(){
+ if ( !$('#reorder').get(0).checked ) {
+ return;
+ }
+
+ var $entry = $(this).parents('.entry_wrapper');
+ var score = $(this).val();
+ if ( score == undefined ) { score = 99999; }
+
+ var $entries = $('.entry_wrapper');
+ for ( var i = 0; i < $entries.length; i++ ) {
+ var $e = $($entries.get(i));
+ var s = $e.find('.title-vote').val();
+ if ( s == "" ) { s = 99999; };
+
+ if ( score < s ) {
+ $e.before($entry);
+ return;
+ }
+ }
+
+ });
});
+
</script>
+<% IF can_vote %>
+<div class="options" align="right">
+<label for="reorder">reorder entries by rank</label>
+<input type="checkbox" id="reorder" checked="checked" />
+</div>
+<% END %>
+
+<div id="entries">
+
<% FOREACH entry IN entries %>
<% SET id = loop.index %>
+<div class="entry_wrapper" id="entry_<% id %>">
<h2>
<% IF can_vote %>
<input type="text" class="title-vote" id="not-votes.<% id %>.score"
@@ -109,8 +143,11 @@ <h2>
<% END %>
</div>
</div>
+</div>
<% END %>
+</div>
+
<% IF can_vote %>
<h2>Cast your vote!</h2>
<div class="entry votepoll">

0 comments on commit 5d0d261

Please sign in to comment.