summaryrefslogtreecommitdiff
path: root/static/website/js/custom.js
blob: 5b584ee103c30bdae1b574ba87fdb35555c0fa91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
$(document).ready(function() {
 $("#id_category").val($category); 

    $tutorial = $("#id_tutorial");
    $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();
        reset("tutorial", "minute_range", "second_range");
        $("#question-details-ok").show();
        var category = $(this).val();
        if(category == "General") {
            $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() {
        /* resetting dropdowns */
        reset("minute_range", "second_range");

        var tutorial = $(this).val();
        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);
                    $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() {
        $.ajax({
            url: "/ajax-similar-questions/",
            type: "POST",
            data: {
                category: $category.val(),
                tutorial: $tutorial.val(),
                minute_range: $minute_range.val(),
                second_range: $second_range.val()
            },
            dataType: "html",
            success: function(data) {
                $response = $(data);
                var similar_count= $response.find("#similar-count").text();
                $("#similar-link").show().html(similar_count);
                $("#modal-body").html(data);
            }
        });
    });


    $(document).ajaxStart(function() {
        $("#ajax-loader").show();
    });

    $(document).ajaxStop(function() {
        $("#ajax-loader").hide();
    });
});