changeset 208:a22259c9862e

Removed redundant code for ratings field and add a separate template file for ratings field. Now ratings will be handled by Jquery.
author Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com>
date Wed, 21 Aug 2013 03:52:06 +0500
parents d534881629ff
children 2a234e11185c
files static/js/agora.js templates/snippet/rate_form.djhtml templates/snippet/snippet_details.djhtml
diffstat 3 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/static/js/agora.js
+++ b/static/js/agora.js
@@ -80,5 +80,9 @@
             currentStyle = newStyle;
         });
     });
+    $("input[name=Rate]").change(function()
+    {
+        $("#rate_form").submit();
+    });
 }
 )(jQuery);
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/templates/snippet/rate_form.djhtml
@@ -0,0 +1,12 @@
+<div id = "radio_votes">
+<form action = "rating/process/"  method = "POST" id="rate_form">
+{% csrf_token%}
+<h3 id ="rate_label">Rate this Snippet:</h3>
+<ul>
+{% for x in "12345" %}
+<li><label for="id_Rate_{{ forloop.counter }}"><input name="Rate" type="radio" class="rate_radio" value="{{ forloop.counter }}" id="id_Rate_0"> {{ forloop.counter }}</label></li>
+{% endfor %}
+</ul>
+<input type="hidden" name="next" value="{{ request.get_full_path }}" />
+</form>
+</div>
\ No newline at end of file
--- a/templates/snippet/snippet_details.djhtml
+++ b/templates/snippet/snippet_details.djhtml
@@ -86,21 +86,7 @@
     {% include "snippet/snippet_box.djhtml" with lines=snippet.content_splitted %}
 
     <br />
-    <div id = "radio_votes">
-
-              <form action = "rating/process/"  method = "POST" id="rate_form">
-              {% csrf_token%}
-              <h3 id ="rate_label">Rate this Snippet:</h3>
-              <ul>
-<li><label for="id_Rate_0"><input name="Rate" onclick="document.getElementById('rate_form').submit();" type="radio" class="rate_radio" value="1" id="id_Rate_0"> 1</label></li>
-<li><label for="id_Rate_1"><input name="Rate" onclick="document.getElementById('rate_form').submit();" type="radio" class="rate_radio" value="2" id="id_Rate_1"> 2</label></li>
-<li><label for="id_Rate_2"><input name="Rate" onclick="document.getElementById('rate_form').submit();" type="radio" class="rate_radio" value="3" id="id_Rate_2"> 3</label></li>
-<li><label for="id_Rate_3"><input name="Rate" onclick="document.getElementById('rate_form').submit();" type="radio" class="rate_radio" value="4" id="id_Rate_3"> 4</label></li>
-<li><label for="id_Rate_4"><input name="Rate" onclick="document.getElementById('rate_form').submit();" type="radio" class="rate_radio" value="5" id="id_Rate_4"> 5</label></li>
-</ul>
-              <input type="hidden" name="next" value="{{ request.get_full_path }}" />
-              </form>
-    </div>
+    {% include "snippet/rate_form.djhtml" %}
     <br/>
     <h2> Comments for this snippet: </h2>{% with snippet as object %}{% include "comments/rawcomment.html" %}{% endwith %}.