File "std-task-discussion.min.js"

Path: /ThinkIB/chem/js/std/std-task-discussionminjs
File size: 4.63 KB
MIME-type: text/plain
Charset: utf-8

 
Open Back
var editor={},commentForm={},fatherIdInput={},cancelCommentPost={},discussionMode="",logger={};function declareInteractionElements(){editor=$("body").find("#editor"),commentForm=$("body").find("#comment-form"),fatherIdInput=$("body").find("#father-id"),cancelCommentPost=$("body").find("#cancel-comment-post")}function saveDiscussionComment(){var content=editor.val(),userId=$("#user-id").val(),userType=$("#user-type").val();if(""==content)return alert("Please, enter a comment."),!1;var stdTaskStudentId=0;1==$("#std-task-id").length&&"student"==userType&&(stdTaskStudentId=$("#std-task-id").val()),$.post("pages/std/std-task-discussion.php?action=add-discussion-comment",{ticket:$("#ticket").val(),user_id:userId,std_task_student_id:stdTaskStudentId,user_type:userType,user_name:$("#user-name").val(),task_id:$("#task-id").val(),father_id:fatherIdInput.val(),content:content,deadline:$("#deadline-time").val()},(function(response){"1"==response.success?(editor.val(""),$("#discussion-form").append(commentForm),getDiscussionList(),discussionMode="",$("div.discussion-msg-ok").text("The message has been added to the discussion"),$("div.discussion-msg-ok").show(),setTimeout((function(){$("div.discussion-msg-ok").hide()}),3e3),editor.attr("placeholder","To start a new thread write your comment here..."),cancelCommentPost.hide(),fatherIdInput.val("0")):alert(response.msg)}),"json")}function editDiscussionComment(ticket,content,commentId){$.post("pages/std/std-task-discussion.php?action=update-discussion-comment",{ticket:ticket,comment_id:commentId,content:content,task_id:$("#task-id").val()},(function(response){"0"==response.success?alert(response.error):(cancelCommentPost.trigger("click"),$("div.discussion-msg-ok").text("The message has been edited successfully"),$("div.discussion-msg-ok").show(),setTimeout((function(){$("div.discussion-msg-ok").hide()}),3e3),fatherIdInput.val("0"))}),"json")}function deleteDiscussionComment(commentId,isFather){$.post("pages/std/std-task-discussion.php?action=delete-discussion-comment",{task_id:$("#task-id").val(),comment_id:commentId,is_father:isFather,ticket:$("#ticket").val()},(function(response){"1"==response.success?getDiscussionList():alert("Error deleting comment: please contact support.")}),"json")}function getDiscussionList(){var sitename=$("#sitename").val();$.post("pages/std/std-task-discussion.php?action=get-discussion-list",{ticket:$("#ticket").val(),task_id:$("#task-id").val(),sitename:sitename},(function(response){"0"==response.success?alert(response.msg):$.when($("#discussion-list").html(response.html)).then(update_local_dates($("#discussion-list")))}),"json")}$(document).ready((function(){catchEventsToTrack();var interactionElementsAreSet=!1;$("#comment-form").length&&declareInteractionElements(),$("#reports-panel").on("mouseenter",$(this),(function(){declareInteractionElements()})),update_local_dates($("#discussion-list")),$("body").on("click","#submit-comment",(function(e){e.preventDefault(),saveDiscussionComment()})),$("body").on("click","a.reply-comment",(function(e){if(e.preventDefault(),""!=discussionMode)return null;discussionMode="reply";var fatherId=$(this).closest(".comment").attr("rel");fatherIdInput.val(fatherId),$(this).closest(".comment").find("> .reply-area").append(commentForm),editor.attr("placeholder","Write your comment here..."),cancelCommentPost.show()})),$("body").on("click","a.edit-comment",(function(e){if(e.preventDefault(),""!=discussionMode)return null;discussionMode="edit";var msgText=$(this).closest(".comment").find("> .comment-content > div").text();$("#comment-form textarea").val(msgText),$(this).closest(".comment").find("> .comment-content").html(commentForm);var commentId=$(this).data("comment-id");$("#submit-comment").hide(),$("#comment-mode").val(commentId),$("#edit-comment").show(),cancelCommentPost.show()})),$("body").on("click","a.delete-comment",(function(e){if(e.preventDefault(),""!=discussionMode)return null;var msg;if(confirm("You are going to delete a comment.\n\nAre you sure?")){var commentId=$(this).data("comment-id"),isFather=0;$("#comm-"+commentId).children(".comment").length>0&&(isFather=1),deleteDiscussionComment(commentId,isFather)}})),$("body").on("click","#cancel-comment-post",(function(e){e.preventDefault(),discussionMode="",$("#discussion-form").append(commentForm),fatherIdInput.val("0"),editor.attr("placeholder","To start a new thread write your comment here...").val(""),getDiscussionList(),$(this).hide(),$("#edit-comment").hide(),$("#submit-comment").show()})),$("body").on("click","#edit-comment",(function(e){e.preventDefault();var content=editor.val(),commentId=$("#comment-mode").val(),ticket;editDiscussionComment($("#comment-ticket").val(),content,commentId)}))}));