diff options
Diffstat (limited to 'static')
-rw-r--r-- | static/forums/templates/user-login.html | 10 | ||||
-rw-r--r-- | static/website/js/custom.js | 100 | ||||
-rw-r--r-- | static/website/templates/ajax-tutorials.html | 2 | ||||
-rw-r--r-- | static/website/templates/new-question.html | 2 |
4 files changed, 82 insertions, 32 deletions
diff --git a/static/forums/templates/user-login.html b/static/forums/templates/user-login.html index 21c4551..ef62ffe 100644 --- a/static/forums/templates/user-login.html +++ b/static/forums/templates/user-login.html @@ -6,6 +6,12 @@ <div class="col-lg-6" style="border-right: 1px dashed #424242;"> <h4>Please login with your <br>Spoken-Tutorial.org account.</h4> <form action="/accounts/login/" method="POST"> {% csrf_token %} + {% if form.errors %} + <div class="alert alert-danger"> + <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> + Invalid username or password + </div> + {% endif %} {% with WIDGET_ERROR_CLASS='field_error' %} <div class="form-group"> <label for="id_username">Username:</label> @@ -39,3 +45,7 @@ </div> <!-- /.col --> </div> <!-- /.row --> {% endblock %} + +{% block javascript %} + $(".alert").alert(); +{% endblock %} diff --git a/static/website/js/custom.js b/static/website/js/custom.js index 49b4053..5565683 100644 --- a/static/website/js/custom.js +++ b/static/website/js/custom.js @@ -4,45 +4,86 @@ $(document).ready(function() { $minute_range = $("#id_minute_range"); $second_range = $("#id_second_range"); + function reset() { + for (var i = 0, l = arguments.length; i < l; i ++) { + switch(arguments[i]) { + case "tutorial": + $tutorial.html("<option value='None'>Select a Tutorial</option>"); + $tutorial.attr("disabled", true); + break; + + case "minute_range": + $minute_range.html("<option value='None'>min</option>"); + $minute_range.attr("disabled", true); + break; + + case "second_range": + $second_range.html("<option value='None'>sec</option>"); + $second_range.attr("disabled", true); + break; + + } + } + } + $category.change(function() { $("#similar-link").hide(); - var category = $(this).val(); + /* resetting dropdowns */ + reset("tutorial", "minute_range", "second_range"); /* see thread-user.js */ $("#question-details-ok").show(); - $.ajax({ - url: "/ajax-tutorials/", - type: "POST", - data: { - category: category - }, - success: function(data) { - $("#id_tutorial").html(data); - $("#id_tutorial").removeAttr("disabled"); - console.log("response = " + data); - } - }); + var category = $(this).val(); + if(category == "General") { + /* disabling all other fields */ + $tutorial.html("<option value='None'>Not required</option>"); + $tutorial.removeAttr("disabled"); + $minute_range.html("<option value='None'>Not required</option>"); + $minute_range.removeAttr("disabled"); + $second_range.html("<option value='None'>Not required</option>"); + $second_range.removeAttr("disabled"); + } else { + $.ajax({ + url: "/ajax-tutorials/", + type: "POST", + data: { + category: category + }, + success: function(data) { + $("#id_tutorial").html(data); + $("#id_tutorial").removeAttr("disabled"); + } + }); + } }); $tutorial.change(function() { - console.log("tut changed"); + /* resetting dropdowns */ + reset("minute_range", "second_range"); var category = $category.val(); var tutorial = $(this).val(); - $.ajax({ - url: "/ajax-duration/", - type: "POST", - data: { - category: category, + if(tutorial == "General") { + /* disabling all other fields */ + $minute_range.html("<option value='None'>Not required</option>"); + $minute_range.removeAttr("disabled"); + $second_range.html("<option value='None'>Not required</option>"); + $second_range.removeAttr("disabled"); + } else { + $.ajax({ + url: "/ajax-duration/", + type: "POST", + data: { + category: category, tutorial: tutorial - }, - success: function(data){ - var $response = $(data); - console.log($response.html()); - $minute_range.html($response.find("#minutes").html()) - $minute_range.removeAttr("disabled"); - $second_range.html($response.find("#seconds").html()) - $second_range.removeAttr("disabled"); - } - }); + }, + success: function(data){ + var $response = $(data); + $minute_range.html($response.find("#minutes").html()) + $minute_range.removeAttr("disabled"); + $second_range.html($response.find("#seconds").html()) + $second_range.removeAttr("disabled"); + } + }); + } }); $second_range.change(function() { @@ -57,7 +98,6 @@ $(document).ready(function() { }, dataType: "html", success: function(data) { - console.log(data); $response = $(data); var similar_count= $response.find("#similar-count").text(); $("#similar-link").show().html(similar_count); diff --git a/static/website/templates/ajax-tutorials.html b/static/website/templates/ajax-tutorials.html index 63e6000..c19fe3c 100644 --- a/static/website/templates/ajax-tutorials.html +++ b/static/website/templates/ajax-tutorials.html @@ -2,4 +2,4 @@ {% for tutorial in tutorials %} <option value="{{ tutorial.tutorial_name }}">{{ tutorial.tutorial_name }}</option> {% endfor %} -<option value="General">General Question</option> +<option value="General">General</option> diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html index 16c6021..28fc707 100644 --- a/static/website/templates/new-question.html +++ b/static/website/templates/new-question.html @@ -11,7 +11,7 @@ {% with WIDGET_ERROR_CLASS='field_error' %} <p> - Please enter the tutorial details. {{ category }} + Please enter the tutorial details. <img id="ajax-loader" src="{% static 'website/images/ajax-loader.gif' %}" style="display:none;"> </p> <div class="row"> |