hint_manager.html 4.48 KB
Newer Older
1 2
<%inherit file="/main.html" />
<%namespace name='static' file='/static_content.html'/>
3
<%namespace name="content" file="/instructor/hint_manager_inner.html"/>
4 5 6


<%block name="headextra">
7 8
  <%static:css group='style-course-vendor'/>
  <%static:css group='style-course'/>
9

10 11 12 13 14 15 16 17 18 19
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/flot/jquery.flot.axislabels.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/jquery-jvectormap-1.1.1/jquery-jvectormap-1.1.1.min.js')}"></script>
  <script type="text/javascript" src="${static.url('js/vendor/jquery-jvectormap-1.1.1/jquery-jvectormap-world-mill-en.js')}"></script>
  <script type="text/javascript" src="${static.url('js/course_groups/cohorts.js')}"></script>

  <script>
    function setup() {
        field = $("#field-label").html()
        changed_votes = []
20
        $(".votes").on('input', function() {
21 22 23 24 25 26 27 28 29
            changed_votes.push($(this))
          });

        $("#hint-delete").click(function(){
            var data_dict = {'op': 'delete hints',
                             'field': field}
            var i = 1
            $(".hint-select").each(function(){
                if ($(this).is(":checked")) {
30 31
                    data_dict[i] = [$(this).parent().attr("data-problem"),
                                    $(this).parent().attr("data-answer"),
32
                                    $(this).parent().attr("data-pk")];
33
                    i += 1
34 35 36
                }
            });
            $.ajax(window.location.pathname, {
37
                type: "POST",
38 39 40 41 42 43 44 45 46
                data: data_dict,
                success: update_contents
            });
        });

        $("#update-votes").click(function(){
            var data_dict = {'op': 'change votes',
                             'field': field}
            for (var i=0; i<changed_votes.length; i++) {
47 48
                data_dict[i] = [$(changed_votes[i]).parent().attr("data-problem"),
                                $(changed_votes[i]).parent().attr("data-answer"),
49 50
                                $(changed_votes[i]).parent().attr("data-pk"),
                                $(changed_votes[i]).val()];
51 52
            }
            $.ajax(window.location.pathname, {
53
                type: "POST",
54 55
                data: data_dict,
                success: update_contents
56
            });
57 58 59 60 61 62 63 64 65
        });

        $("#switch-fields").click(function(){
            out_dict = {'op': 'switch fields',
                        'field': $(this).attr("other-field")};
            $.ajax(window.location.pathname, {
                type: "POST",
                data: out_dict,
                success: update_contents
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
        $(".submit-new-hint").click(function(){
            problem_name = $(this).data("problem");
            hint_text = $(".submit-hint-text").filter('*[data-problem="'+problem_name+'"]').val();
            hint_answer = $(".submit-hint-answer").filter('*[data-problem="'+problem_name+'"]').val();
            data_dict = {'op': 'add hint',
                         'field': field,
                         'problem': problem_name,
                         'answer': hint_answer,
                         'hint': hint_text};
            $.ajax(window.location.pathname, {
                type: "POST",
                data: data_dict,
                success: update_contents
            });
        });

        $("#approve").click(function(){
            var data_dict = {'op': 'approve',
                             'field': field}
            var i = 1
            $(".hint-select").each(function(){
                if ($(this).is(":checked")) {
92 93
                    data_dict[i] = [$(this).parent().attr("data-problem"),
                                    $(this).parent().attr("data-answer"),
94 95 96 97 98
                                    $(this).parent().attr("data-pk")];
                    i += 1
                }
            });
            $.ajax(window.location.pathname, {
99
                type: "POST",
100 101 102 103
                data: data_dict,
                success: update_contents
            });
        });
104 105 106
    }

    $(document).ready(setup);
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    function update_contents(data, status, jqXHR) {
        $('.instructor-dashboard-content').html(data.contents);
        setup();

    }

  </script>

</%block>

<section class="container">
<div class="instructor-dashboard-wrapper">

    <section class="instructor-dashboard-content">
        ${content.main()}
    </section>

</div>
</section>