summaryrefslogtreecommitdiff
path: root/js/tbc-download.js
blob: 04b7633abb3aec09b5f5b1463c78906ad5e09ae5 (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
115
116
117
$(document).ready(function(){
    //webroot = "http://"+location.hostname+"/";
    webroot = Drupal.settings.basePath;
    $('.tbc-category').live('change', function(){
        tbc_category = $('.tbc-category').val();
        $('.tbc-book-overall').css({'display' : 'none'});
        if(tbc_category != 0) {
            $.ajax({
                type : 'POST',
                url : webroot + "textbook_run_ajax",
                data : {
                    'category' : tbc_category
                },
                beforeSend: function() {
                },
                success : function(data) {
                    output = JSON.parse(data);
                    console.log(output['books']);
                    html_data = '';
                    $.each( output['books'], function( key, value ) {
                        html_data += "<option value='"+ key +"'>" + value + "</option>";
                    });
                    $('.tbc-book').html(html_data);
                    $('.tbc-book-main').css({'display' : 'block'});
                }
            });
        }
    });

    $('.tbc-book').live('change', function(){
        tbc_category = $('.tbc-category').val();
        tbc_book = $('.tbc-book').val();
        $('.tbc-after-book').css({'display' : 'none'});
        if(tbc_category != 0 && tbc_book != 0) {
            $.ajax({
                type : 'POST',
                url : webroot + "textbook_run_ajax",
                data : {
                    'category' : tbc_category,
                    'book' : tbc_book
                },
                beforeSend: function() {
                },
                success : function(data){
                    output = JSON.parse(data);
                    $('.tbc-book-details').html(output['details']);
                    $('.tbc-book-download').html(output['download']);
                    $('.tbc-book-download-pdf').html(output['downloadpdf']);
                    html_data = '';
                    $.each( output['chapters'], function( key, value ) {
                        html_data += "<option value='"+ key +"'>" + value + "</option>";
                    });
                    $('.tbc-chapter').html(html_data);
                    $('.tbc-book-block').css({'display' : 'block'});
                }
            });
        }
    });

    $('.tbc-chapter').live('change', function(){
        tbc_category = $('.tbc-category').val();
        tbc_book = $('.tbc-book').val();
        tbc_chapter = $('.tbc-chapter').val();
        $('.tbc-after-chapter').css({'display' : 'none'});
        if(tbc_category != 0 && tbc_book != 0 && tbc_chapter != 0) {
            $.ajax({
                type : 'POST',
                url : webroot + "textbook_run_ajax",
                data : {
                    'category' : tbc_category,
                    'book' : tbc_book,
                    'chapter': tbc_chapter
                },
                beforeSend: function() {
                },
                success : function(data){
                    output = JSON.parse(data);
                    $('.tbc-chapter-download').html(output['download']);
                    html_data = '';
                    $.each( output['examples'], function( key, value ) {
                        html_data += "<option value='"+ key +"'>" + value + "</option>";
                    });
                    $('.tbc-example').html(html_data);
                    $('.tbc-chapter-block').css({'display' : 'block'});
                }
            });
        }
    });

    $('.tbc-example').live('change', function(){
        tbc_category = $('.tbc-category').val();
        tbc_book = $('.tbc-book').val();
        tbc_chapter = $('.tbc-chapter').val();
        tbc_example = $('.tbc-example').val();
        $('.tbc-after-example').css({'display' : 'none'});
        if(tbc_category != 0 && tbc_book != 0 && tbc_chapter != 0 && tbc_example != 0) {
            $.ajax({
                type : 'POST',
                url : webroot + "textbook_run_ajax",
                data : {
                    'category' : tbc_category,
                    'book' : tbc_book,
                    'chapter': tbc_chapter,
                    'example': tbc_example
                },
                beforeSend: function() {
                },
                success : function(data){
                    output = JSON.parse(data);
                    $('.tbc-example-download').html(output['download']);
                    $('.tbc-example-files').html(output['files']);
                    $('.tbc-after-example').css({'display' : 'block'});
                }
            });
        }
    });
});