diff options
author | Byron Jones <glob@mozilla.com> | 2015-10-15 17:59:10 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2015-10-15 17:59:10 +0200 |
commit | 2e2981d25c185fde56f29c7aed4e3e6bba50039e (patch) | |
tree | 725b4a4b7de9d444ce2b84e9cedce3dc8d7f7896 /extensions/EditComments/web/js | |
parent | 5265c09db899e148ceef6ba47aa199fa1e282e7b (diff) | |
download | bugzilla-2e2981d25c185fde56f29c7aed4e3e6bba50039e.tar.gz bugzilla-2e2981d25c185fde56f29c7aed4e3e6bba50039e.tar.xz |
Bug 1153101 - add hooks for edit-comments extension
Diffstat (limited to 'extensions/EditComments/web/js')
-rw-r--r-- | extensions/EditComments/web/js/editcomments.js | 132 |
1 files changed, 52 insertions, 80 deletions
diff --git a/extensions/EditComments/web/js/editcomments.js b/extensions/EditComments/web/js/editcomments.js index a4e3014d5..222c081cf 100644 --- a/extensions/EditComments/web/js/editcomments.js +++ b/extensions/EditComments/web/js/editcomments.js @@ -6,87 +6,59 @@ * defined by the Mozilla Public License, v. 2.0. */ -function editComment(comment_count, comment_id) { - if (!comment_count || !comment_id) return; +$(function() { + $('.edit-comment-btn') + .click(function(event) { + event.preventDefault(); + var that = $(this); + var id = that.data('id'); + var no = that.data('no'); - var edit_comment_textarea = YAHOO.util.Dom.get('edit_comment_textarea_' + comment_count); - if (!YAHOO.util.Dom.hasClass(edit_comment_textarea, 'bz_default_hidden')) { - hideEditCommentField(comment_count); - return; - } - - // Show the loading indicator - toggleCommentLoading(comment_count); - - YAHOO.util.Connect.setDefaultPostHeader('application/json', true); - YAHOO.util.Connect.asyncRequest( - 'POST', - 'jsonrpc.cgi', - { - success: function(res) { - // Hide the loading indicator - toggleCommentLoading(comment_count); - data = YAHOO.lang.JSON.parse(res.responseText); - if (data.error) { - alert("Get [% comment failed: " + data.error.message); - } - else if (data.result.comments[comment_id]) { - var comment_text = data.result.comments[comment_id]; - showEditCommentField(comment_count, comment_text); - } - }, - failure: function(res) { - // Hide the loading indicator - toggleCommentLoading(comment_count); - if (res.responseText) { - alert("Get comment failed: " + res.responseText); - } - } - }, - YAHOO.lang.JSON.stringify({ - version: "1.1", - method: "EditComments.comments", - id: comment_id, - params: { comment_ids: [ comment_id ], - Bugzilla_api_token : (BUGZILLA.api_token ? BUGZILLA.api_token : '') + // cancel editing + if (that.data('editing')) { + that.data('editing', false).text('Edit'); + $('#edit_comment_textarea_' + id).remove(); + $('#ct-' + no).show(); + return; } - }) - ); -} - -function hideEditCommentField(comment_count) { - var comment_text_pre = YAHOO.util.Dom.get('comment_text_' + comment_count); - YAHOO.util.Dom.removeClass(comment_text_pre, 'bz_default_hidden'); + that.text('Unedit'); - var edit_comment_textarea = YAHOO.util.Dom.get('edit_comment_textarea_' + comment_count); - YAHOO.util.Dom.addClass(edit_comment_textarea, 'bz_default_hidden'); - edit_comment_textarea.disabled = true; - - YAHOO.util.Dom.get("edit_comment_edit_link_" + comment_count).innerHTML = "edit"; -} - -function showEditCommentField(comment_count, comment_text) { - var comment_text_pre = YAHOO.util.Dom.get('comment_text_' + comment_count); - YAHOO.util.Dom.addClass(comment_text_pre, 'bz_default_hidden'); - - var edit_comment_textarea = YAHOO.util.Dom.get('edit_comment_textarea_' + comment_count); - YAHOO.util.Dom.removeClass(edit_comment_textarea, 'bz_default_hidden'); - edit_comment_textarea.disabled = false; - edit_comment_textarea.value = comment_text; - - YAHOO.util.Dom.get("edit_comment_edit_link_" + comment_count).innerHTML = "unedit"; -} - -function toggleCommentLoading(comment_count, hide) { - var comment_div = 'comment_text_' + comment_count; - var loading_div = 'edit_comment_loading_' + comment_count; - if (YAHOO.util.Dom.hasClass(loading_div, 'bz_default_hidden')) { - YAHOO.util.Dom.addClass(comment_div, 'bz_default_hidden'); - YAHOO.util.Dom.removeClass(loading_div, 'bz_default_hidden'); - } - else { - YAHOO.util.Dom.removeClass(comment_div, 'bz_default_hidden'); - YAHOO.util.Dom.addClass(loading_div, 'bz_default_hidden'); - } -} + // replace comment <pre> with loading message + $('#ct-' + no) + .hide() + .after( + $('<pre/>') + .attr('id', 'edit-comment-loading-' + id) + .addClass('edit-comment-loading') + .text('Loading...') + ); + // load original comment text + bugzilla_ajax( + { + url: 'rest/editcomments/comment/' + id, + hideError: true + }, + function(data) { + // create editing textarea + $('#edit-comment-loading-' + id).remove(); + that.data('editing', true); + $('#ct-' + no) + .after( + $('<textarea/>') + .attr('name', 'edit_comment_textarea_' + id) + .attr('id', 'edit_comment_textarea_' + id) + .addClass('edit-comment-textarea') + .val(data.comments[id]) + ); + }, + function(message) { + // unedit and show message + that.data('editing', false).text('Edit'); + $('#edit-comment-loading-' + id).remove(); + $('#ct-' + no).show(); + alert(message); + } + ); + }); +}); |