File "std-task-utils.min.js"
Path: /ThinkIB/js/std/std-task-utilsminjs
File size: 12.92 KB
MIME-type: text/plain
Charset: utf-8
function setShowResultsListeners(element){element.on("click",".show-read-history",(function(e){e.preventDefault();var title="";title=$(this).closest("tr").find("td.task a").length>0?$(this).closest("tr").find("td.task a").text():$(this).find("h4").text();var linkToTask=$(this).data("url-task");$("#modal-log-res-title").html(""),$("#modal-log-details-table tbody").html(""),$("#modal-log-details-visits").html(""),$("#modal-log-total-time").text(""),$(".open-task-browser").remove(),$("#modal-log-details div.loading-student-log").show();var url="pages/std/std-dashboard.php?action=get-read-history",data={ticket:$("#ticket").val(),task_id:$(this).data("task-id"),student_id:$(this).data("std-id")};$.post(url,data,(function(response){if("1"==response.success){if($("#modal-log-details div.loading-student-log").hide(),$("#modal-log-res-title").html('<i class="fa fa-file colored"></i>'+title),void 0!==linkToTask&&null==linkToTask.match(/.*?\/exam\/.*?\//gm)){var openLink=['<a class="open-task-browser" href="'+linkToTask+'" target="_blank">','<i class="fa fa-external-link"></i> Open page',"</a>"].join("");$("#modal-log-res-title").after(openLink)}$("#modal-log-details-table tbody").html(response.html),$("#modal-log-details-visits").html('<h5 style="margin-top: 0;">Total visits: <strong>'+response.n_visits+"</strong></h5>"),$("#modal-log-total-time").text(response.time)}else alert(response.msg)}),"json"),$("#modal-log-details").modal("show")})),element.on("click",".show-quiz-history",(function(e){e.preventDefault();var item=$(this),title="";title=$(this).closest("tr").find("td.task a").length>0?$(this).closest("tr").find("td.task a").text():$(this).find("h4").clone().children().remove().end().text();var linkToTask=$(this).data("url-task");$("#modal-std-quiz-title").html(""),$("#modal-std-quiz-score-log").html(""),$("#modal-std-quiz-exam-log").html(""),$("#modal-std-quiz-thread").html(""),$("#modal-std-quiz-table-contents").html(""),$(".open-task-browser").remove(),$("#modal-std-quiz div.loading-student-quiz").show();var url="pages/std/std-dashboard.php?action=get-quiz-history",data={ticket:$("#ticket").val(),task_id:$(this).data("task-id"),student_id:$(this).data("std-id"),type:"quiz"};$.post(url,data,(function(response){if("1"==response.success){if($("#modal-std-quiz div.loading-student-quiz").hide(),$("#modal-std-quiz-title").html('<i class="fa fa-puzzle-piece colored"></i>'+title),null==linkToTask.match(/.*?\/exam\/.*?\//gm)){var openLink=['<a class="open-task-browser" href="'+linkToTask+'" target="_blank">','<i class="fa fa-external-link"></i> Open task in page',"</a>"].join("");$("#modal-std-quiz-title").after(openLink)}if($("#modal-std-quiz-details").html(response.header),$("#modal-std-quiz-score-log").html(response.score_log),$("#modal-std-quiz-exam-log").html(response.exam_log),$("#modal-std-quiz-thread").html(response.thread),$("#modal-std-quiz div.modal-body #modal-std-quiz-table-contents").html(response.table_body),$("#modal-std-quiz").css({width:parseInt(.6*$(window).width())+"px","margin-left":"-"+parseInt(.6*$(window).width()/2)+"px"}),$("#modal-std-quiz .modal-body, .modal-footer").css("overflow-y","auto"),$("#modal-std-quiz .modal-body").css("max-height",.5*$(window).height()+"px"),numberQuizQuestions(),addLettersBeforeOptions(),MathLive.renderMathInDocument(),item.closest("li.notification").length){var list=item.closest("li.notification");toggleNotificationRead(list)}}else alert(response.msg)}),"json"),$("#modal-std-quiz .modal-body").css("max-height",parseInt(.6*$(window).height())+"px"),$("#modal-std-quiz").modal("show"),$("#modal-std-quiz").on("shown.bs.modal",(function(){update_local_dates($("#modal-std-quiz")),MathLive.renderMathInDocument(),getLengthTextInputs()}))})),element.on("click",".show-quiz-page-history",(function(e){e.preventDefault();var item=$(this),title="";title=$(this).closest("tr").find("td.task a").length>0?$(this).closest("tr").find("td.task a").text():$(this).find("h4").length>0?$(this).find("h4").clone().children().remove().end().text():$(this).closest("#main-column").find("h1.section-title").text();var linkToTask=$(this).data("url-task");$("#modal-std-quiz-title").html(""),$("#modal-std-quiz-score-log").html(""),$("#modal-std-quiz-exam-log").html(""),$("#modal-std-quiz-thread").html(""),$("#modal-std-quiz-table-contents").html(""),$(".open-task-browser").remove(),$("#modal-std-quiz div.loading-student-quiz").show();var url="pages/std/std-dashboard.php?action=get-quiz-history",data={ticket:$("#ticket").val(),task_id:$(this).data("task-id"),student_id:$(this).data("std-id"),type:"quiz-page"};$.post(url,data,(function(response){if("1"==response.success){if($("#modal-std-quiz div.loading-student-quiz").hide(),$("#modal-std-quiz-title").html('<i class="fa fa-puzzle-piece colored"></i> '+title),void 0!==linkToTask&&null==linkToTask.match(/.*?\/exam\/.*?\//gm)){var openLink=['<a class="open-task-browser" href="'+linkToTask+'" target="_blank">','<i class="fa fa-external-link"></i> Open task in page',"</a>"].join("");$("#modal-std-quiz-title").after(openLink)}if($("#modal-std-quiz-details").html(response.header),$("#modal-std-quiz-score-log").html(response.score_log),$("#modal-std-quiz-exam-log").html(response.exam_log),$("#modal-std-quiz-thread").html(response.thread),$("#modal-std-quiz div.modal-body #modal-std-quiz-table-contents").html(response.table_body),$("#modal-std-quiz").css({width:parseInt(.6*$(window).width())+"px","margin-left":"-"+parseInt(.6*$(window).width()/2)+"px"}),$("#modal-std-quiz .modal-body, .modal-footer").css("overflow-y","auto"),$("#modal-std-quiz .modal-body").css("max-height",.5*$(window).height()+"px"),numberQuizQuestions(),addLettersBeforeOptions(),MathLive.renderMathInDocument(),item.closest("li.notification").length){var list=item.closest("li.notification");toggleNotificationRead(list)}$("#modal-std-quiz").on("shown.bs.modal",(function(){update_local_dates($("#modal-std-quiz")),MathLive.renderMathInDocument(),getLengthTextInputs()}))}else alert(response.msg)}),"json"),$("#modal-std-quiz .modal-body").css("max-height",parseInt(.6*$(window).height())+"px"),$("#modal-std-quiz").modal("show")})),element.on("click",".show-write-history, .show-short-answer-history",(function(e){e.preventDefault();var item=$(this),taskId=$(this).data("task-id"),studentId=$(this).data("std-id");if($("#std-new-messages").length){var taskLink=$("#std-new-messages ul").find('a[data-task-id="'+taskId+'"]');taskLink.length&&taskLink.closest("li").remove()}$("#std-tasks-table-completed td").find('a.msg-link[data-task-id="'+taskId+'"]').length&&$("#std-tasks-table-completed td").find('a.msg-link[data-task-id="'+taskId+'"]').remove(),$(this).find("h4.unread-msgs").length&&$(this).find("h4.unread-msgs").removeClass("unread-msgs");var title=taskType="";if($(this).closest("td.task").length>0?taskType=$(this).closest("td.task").data("type"):taskType=$(this).data("task-type"),"short-answer"==taskType){var linkToTask=$(this).data("url-task");void 0!==linkToTask&&null==linkToTask.match(/.*?\/exam\/.*?\//gm)&&(title+=['<a class="open-task-browser" href="'+linkToTask+'" target="_blank">','<i class="fa fa-external-link"></i> Open task in page',"</a>"].join(""))}var url="pages/std/std-dashboard.php?action=get-write-history",data={ticket:$("#ticket").val(),task_id:taskId,student_id:studentId};$.post(url,data,(function(response){if("1"==response.success){$("#modal-std-write .modal-header span").html(response.header),$("#modal-std-write .modal-header span").append(title),$("#modal-std-write .modal-body #modal-std-write-details").html(response.details),$("#modal-std-write .modal-body #modal-std-write-response").html(response.body),$("#modal-std-write .modal-body .threads-box").html(response.threads),$("#modal-std-write .modal-footer").html(response.footer),$("#modal-std-write .modal-body #modal-std-write-response").find(".std-manual-answer").each((function(){$(this).addClass("well"),$(this).find("p").last().css("margin-bottom","0px")})),adjustModal($("#modal-std-write")),$("#modal-std-write-response").find('span.inline-hl[data-status="saved"]').length&&($("#modal-std-write-response").find('span.inline-hl[data-status="saved"]').each((function(){var spanId=$(this).data("comment");$("#modal-std-write-response").find('span.inline-cm[data-comment="'+spanId+'"]').remove()})),$("#modal-std-write-response").find('span.inline-hl[data-status="saved"]').contents().unwrap(),$("#modal-std-write-response").find("p").each((function(){this.normalize()}))),$("#modal-std-write").modal("show"),$("#modal-std-write").one("shown.bs.modal",(function(){update_local_dates($("#modal-std-write")),$(".notes-log-reports").is(":empty")&&$(".notes-log-reports").css({border:"none",margin:"0",padding:"0"}),$(".thread-list").is(":empty")&&$(".thread-list").css({border:"none",padding:"0","overflow-y":"unset"}),"short-answer"==taskType&&(null!=response.tib_quizzes&&$.when(getEditorAnswers(response.tib_quizzes)).then((function(answers){appendEditorAnswers($("#modal-write-std-task"),answers,"right")})),showEssayWordLimit(),$("p.std-manual-answer").filter((function(i,a){return 0==$.trim($(a).text()).length})).append('<span class="std-no-manual-answer">No answer submitted</span>'))}));var answerContainer=$("#modal-std-write").find(".std-write-response-box"),originalY=0;if(answerContainer.css("position","relative"),$("#modal-std-write").find("#modal-write-std-task").on("scroll",(function(){var scrollTop=$(this).scrollTop();answerContainer.stop(!1,!1).animate({top:scrollTop-0},150)})),$("#std-new-messages ul").find("li").length){var nMsgs=$("#std-new-messages ul").find("li").length;$("#std-new-messages a.dropdown-toggle").find("span.unread-msgs").text(nMsgs)}else $("#std-new-messages").remove();if(item.closest("li.notification").length){var list=item.closest("li.notification");toggleNotificationRead(list)}MathLive.renderMathInDocument()}else alert(response.msg)}),"json")})),element.on("click",".show-discussion-history, .show-written-answer-history, .show-model-answer-history",(function(e){e.preventDefault();var linkToTask=$(this).data("url-task");window.open(linkToTask,"_blank")}))}function adjustModal(modal){modal.css({width:.8*$(window).width()+"px","margin-left":"-"+.8*$(window).width()/2+"px"}),modal.find(".modal-body").css("max-height","calc(100vh - "+.4*$(window).height()+"px)"),modal.find(".modal-body, .modal-footer").css("overflow-y","auto"),modal.find(".modal-footer").css("max-height",.2*$(window).height()+"px")}function focusStdComment(element,answerBox,commentsBox){element.on("click","mark.highlight",(function(e){e.preventDefault();var markId,id=$(this).attr("class").match(/\bhl-[\w-]*\b/)[0].replace("hl-",""),scrollTop=commentsBox.find('.comment[data-index="'+id+'"]').data("top");answerBox.animate({scrollTop:scrollTop},150)}))}function addMarksThreads(element){element.on("click","#send-msg",(function(e){e.preventDefault();var threads=[];void 0!==$("#student-msg").val()&&$("#student-msg").val().length>0&&threads.push({father:$("#student-msg").data("father"),content:$("#student-msg").val()}),sendStdMarksComments(threads,"student")}))}function sendStdMarksComments(comments,userType){var taskStdId=$("#send-msg").data("std-task-id"),stdId=$("#send-msg").data("std-id"),stdName=$("#send-msg").data("std-name"),url="/pages/std/std-dashboard.php?action=send-threads",data={ticket:$("#ticket").val(),"std-task-id":taskStdId,"user-id":stdId,"user-type":userType,"std-comments":comments.length>0?comments:null};$.post(url,data,(function(response){1==response.success?(response.threads.length>0&&($(".thread-list").is(":empty")&&($(".thread-list").before($('<label class="threads-header">Teacher comments</label>')),$(".thread-list").css({border:"1px solid #e3e3e3",padding:"5px","overflow-y":"auto"})),$.each(response.threads,(function(i,t){$(".thread-list").append(['<div class="thread-'+t.id+'">','<div class="comment-content" style="margin-left: 30px;">',"<strong><small>"+stdName+"</small></strong>",t.created,'<img class="userpic thumb pull-left" src="'+t.userpic+'">','<div class="thread-content">'+nl2br(t.content)+"</div>","</div>","</div>"].join(""))})),$("textarea#student-msg").val(""),update_local_dates($(".thread-list"))),showSuccessMessage($(".comment-box-msg"),"Changes successfully sent")):alert(response.msg)}),"json")}function orderingPendingTasks(listener,drawer){$("#"+listener).change((function(){var ticket=$("#ticket").val(),optionSelected=$(this).val(),groupId=void 0!==$(this).data("group-id")?$(this).data("group-id"):null,generalId=void 0!==$(this).data("general-id")?$(this).data("general-id"):null;$.post("pages/std/std-dashboard.php?action=order-by-date",{ticket:ticket,order_by_date:optionSelected,group_id:groupId,general_id:generalId},(function(response){1===response.success?($("#"+drawer).html(response.html),assignmentsListItemClickListener()):alert("Error (SD-01): There was an error: Please contact support")}),"json")})),assignmentsListItemClickListener()}function assignmentsListItemClickListener(){$(".assignments-list-item").on("click",(function(e){var linkToTask=$(this).attr("data-href");""!=linkToTask?window.location=linkToTask:alert("You have already done this exam task and cannot repeat it.")}))}