summaryrefslogtreecommitdiff
path: root/static/website/js/search.js
blob: 5973e79958824718e051252c5ae6cadb1eafec9c (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
$(document).ready(function() {
    $search_key = $("#search-key");
    $search_key_submit = $("#search-key-submit");
    $keyword_search_results = $("#keyword-search-results");

    $search_key.keyup(function(e) {
        if(e.keyCode == 13) {
            $search_key_submit.click();
        }
    });

    $search_key_submit.click(function() {
        var key = $search_key.val();
        $.ajax({
            url: "/ajax-keyword-search/",
            type: "POST",
            data: {
                key: key
            },
            dataType: "html",
            success: function(data) {
                $keyword_search_results.html(data);
                console.log(data);
            }
        });
    });

    $search_time_submit = $("#search-time-submit");
    $category = $("#search-category");
    $tutorial = $("#search-tutorial");
    $minute_range = $("#search-minute-range");
    $second_range = $("#search-second-range");
    $time_search_results = $("#time-search-results");

    $category.change(function() {
        var category = $(this).val();
        $.ajax({
            url: "/ajax-tutorials/",
            type: "POST",
            data: {
                category: category
            },
            success: function(data) {
                $tutorial.html(data);
                $tutorial.removeAttr("disabled");
                console.log("response = " + data);
            }
        });
    });

    $tutorial.change(function() {
        console.log("tut changed");
        var category = $category.val();
        var tutorial = $(this).val();
        $.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");
            }
        });
    });

    $search_time_submit.click(function() {
        $.ajax({
            url: "/ajax-time-search/",
            type: "POST",
            data: {
                category: $category.val(),
                tutorial: $tutorial.val(),
                minute_range: $minute_range.val(),
                second_range: $second_range.val()
            },
            dataType: "html",
            success: function(data) {
                console.log(data);
                $time_search_results.html(data);
            }
        });
    });
    
});