summaryrefslogtreecommitdiff
path: root/static/website/js/custom.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/website/js/custom.js')
-rw-r--r--static/website/js/custom.js100
1 files changed, 70 insertions, 30 deletions
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);