define('jira/viewissue/comment/footer-comment', ['jira/viewissue/comment/comment-form', 'jquery'], function(commentForm, $) { /** * This is used to control the logic of showing confirmation dialog. * If the comment form is being submitted, there should be no confirmation dialog appearing at all. * Its value will be changed when successfully submitting the form and start opening a new form. * @type {boolean} */ var commentFormIsBeingSubmitted = false; var isInPreviewMode = false; var footerComment = { /** * Gets comment module * @return {jQuery} */ getModule: function () { return $("#addcomment"); }, /** * Is the comment area visible * @return {*} */ isActive: function () { return this.getModule().hasClass("active"); }, /** * Hides comment area * * @param cancel - clear textarea */ hide: function (cancel) { if (this.isActive()) { var dirtyMessage = commentForm.handleBrowseAway(); if (isInPreviewMode || commentFormIsBeingSubmitted || !dirtyMessage || confirm(dirtyMessage)) { this.getModule().removeClass("active"); commentForm.hide(cancel); } } }, ajaxSubmit: function () { commentFormIsBeingSubmitted = true; commentForm.ajaxSubmit().then(function () { footerComment.hide(true); }); }, /** * Shows comment area */ show: function () { if (!this.isActive()) { commentFormIsBeingSubmitted = false; this.getModule().addClass("active"); this.appendForm(); commentForm.show(); } else { commentForm.focusField(); } }, /** * Appends form to correct location */ appendForm: function () { this.getModule().find(".mod-content").append(commentForm.getForm()); } }; footerComment.setPreviewMode = function(isEnabled) { isInPreviewMode = Boolean(isEnabled); }; return footerComment; });