From 214d8696fafee4e38c6bf039315aac37e4cd2e2b Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 21 Jul 2015 18:02:56 +0530 Subject: Add filters to question display --- testapp/exam/static/exam/js/question_filter.js | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 testapp/exam/static/exam/js/question_filter.js (limited to 'testapp/exam/static') diff --git a/testapp/exam/static/exam/js/question_filter.js b/testapp/exam/static/exam/js/question_filter.js new file mode 100644 index 0000000..7dc92a6 --- /dev/null +++ b/testapp/exam/static/exam/js/question_filter.js @@ -0,0 +1,69 @@ +$(document).ready(function(){ + $question_type = $("#id_question_type"); + $marks = $("#id_marks"); + $language = $("#id_language"); + + $question_type.change(function() { + $.ajax({ + url: "/exam/ajax/questions/filter/", + type: "POST", + data: { + question_type: $question_type.val(), + marks: $marks.val(), + language: $language.val() + }, + dataType: "html", + success: function(output) { + var questions = $(output).filter("#questions").html(); + $("#filtered-questions").html(questions); + } + }); + }); + + $language.change(function() { + $.ajax({ + url: "/exam/ajax/questions/filter/", + type: "POST", + data: { + question_type: $question_type.val(), + marks: $marks.val(), + language: $language.val() + }, + dataType: "html", + success: function(output) { + var questions = $(output).filter("#questions").html(); + $("#filtered-questions").html(questions); + } + }); + }); + + $marks.change(function() { + $.ajax({ + url: "/exam/ajax/questions/filter/", + type: "POST", + data: { + question_type: $question_type.val(), + marks: $marks.val(), + language: $language.val() + }, + dataType: "html", + success: function(output) { + var questions = $(output).filter("#questions").html(); + $("#filtered-questions").html(questions); + } + }); + }); + + $("#checkall").live("click", function(){ + if($(this).attr("checked")) { + $("#filtered-questions input:checkbox").each(function(index, element) { + $(this).attr('checked','checked'); + }); + } + else { + $("#filtered_questions input:checkbox").each(function(index, element) { + $(this).removeAttr('checked'); + }); + } + }); +}); \ No newline at end of file -- cgit From dbab99bc13b8483c24706e47a9a0926508e3c332 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 23 Jul 2015 16:32:13 +0530 Subject: Add filters: Minor fixes --- testapp/exam/static/exam/js/question_filter.js | 42 ++++++-------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'testapp/exam/static') diff --git a/testapp/exam/static/exam/js/question_filter.js b/testapp/exam/static/exam/js/question_filter.js index 7dc92a6..065b06b 100644 --- a/testapp/exam/static/exam/js/question_filter.js +++ b/testapp/exam/static/exam/js/question_filter.js @@ -3,7 +3,7 @@ $(document).ready(function(){ $marks = $("#id_marks"); $language = $("#id_language"); - $question_type.change(function() { + function question_filter() { $.ajax({ url: "/exam/ajax/questions/filter/", type: "POST", @@ -18,51 +18,29 @@ $(document).ready(function(){ $("#filtered-questions").html(questions); } }); + } + + $question_type.change(function() { + question_filter() }); $language.change(function() { - $.ajax({ - url: "/exam/ajax/questions/filter/", - type: "POST", - data: { - question_type: $question_type.val(), - marks: $marks.val(), - language: $language.val() - }, - dataType: "html", - success: function(output) { - var questions = $(output).filter("#questions").html(); - $("#filtered-questions").html(questions); - } - }); + question_filter() }); $marks.change(function() { - $.ajax({ - url: "/exam/ajax/questions/filter/", - type: "POST", - data: { - question_type: $question_type.val(), - marks: $marks.val(), - language: $language.val() - }, - dataType: "html", - success: function(output) { - var questions = $(output).filter("#questions").html(); - $("#filtered-questions").html(questions); - } - }); + question_filter() }); $("#checkall").live("click", function(){ if($(this).attr("checked")) { $("#filtered-questions input:checkbox").each(function(index, element) { - $(this).attr('checked','checked'); + $(this).attr('checked', true); }); } else { - $("#filtered_questions input:checkbox").each(function(index, element) { - $(this).removeAttr('checked'); + $("#filtered-questions input:checkbox").each(function(index, element) { + $(this).attr('checked', false); }); } }); -- cgit