summaryrefslogtreecommitdiffstats
path: root/extensions/EditComments/web
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/EditComments/web')
-rw-r--r--extensions/EditComments/web/js/editcomments.js132
-rw-r--r--extensions/EditComments/web/styles/editcomments.css22
2 files changed, 72 insertions, 82 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);
+ }
+ );
+ });
+});
diff --git a/extensions/EditComments/web/styles/editcomments.css b/extensions/EditComments/web/styles/editcomments.css
index 911896ac8..99f4f9690 100644
--- a/extensions/EditComments/web/styles/editcomments.css
+++ b/extensions/EditComments/web/styles/editcomments.css
@@ -5,6 +5,24 @@
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0. */
-.edit_comment_textarea {
- width: 845px;
+.edit-comment-textarea {
+ width: 100%;
+ height: 15em;
+}
+
+.edit-comment-loading {
+ background: #fff;
+ padding: 8px;
+ border-top: 1px solid #ddd;
+ margin: 1px 0 0;
+ font-style: italic;
+}
+
+.edit-head {
+ width: 50em;
+ padding: 10px;
+}
+
+.edit-head .vcard {
+ display: inline;
}