diff options
author | lpsolit%gmail.com <> | 2009-06-23 01:44:33 +0200 |
---|---|---|
committer | lpsolit%gmail.com <> | 2009-06-23 01:44:33 +0200 |
commit | 0ccecfb569714e133ffedbc0eb9a7a88c5abba19 (patch) | |
tree | 5e4872ad395e2a0d9ce4eabfe811996b275d5b8a | |
parent | c159b971108a88dcd6e2e0cc04f7b4e6809bedc0 (diff) | |
download | bugzilla-0ccecfb569714e133ffedbc0eb9a7a88c5abba19.tar.gz bugzilla-0ccecfb569714e133ffedbc0eb9a7a88c5abba19.tar.xz |
Bug 477464: Move JS code out of attachment/edit.html.tmpl - Patch by Nitish Bezzala <nbezzala@yahoo.com> r/a=LpSolit
-rw-r--r-- | js/attachment.js | 119 | ||||
-rw-r--r-- | template/en/default/attachment/edit.html.tmpl | 139 |
2 files changed, 128 insertions, 130 deletions
diff --git a/js/attachment.js b/js/attachment.js index 254331679..d3ba26796 100644 --- a/js/attachment.js +++ b/js/attachment.js @@ -208,3 +208,122 @@ function get_tbody_from_twisty(twisty) { function get_twisty_from_tbody(tbody) { return tbody.previousSibling.firstChild.nextSibling.firstChild.firstChild; } + +var prev_mode = 'raw'; +var current_mode = 'raw'; +var has_edited = 0; +var has_viewed_as_diff = 0; +function editAsComment(patchviewerinstalled) +{ + switchToMode('edit', patchviewerinstalled); + has_edited = 1; +} +function undoEditAsComment(patchviewerinstalled) +{ + switchToMode(prev_mode, patchviewerinstalled); +} +function redoEditAsComment(patchviewerinstalled) +{ + switchToMode('edit', patchviewerinstalled); +} + +function viewDiff(attachment_id, patchviewerinstalled) +{ + switchToMode('diff', patchviewerinstalled); + + // If we have not viewed as diff before, set the view diff frame URL + if (!has_viewed_as_diff) { + var viewDiffFrame = document.getElementById('viewDiffFrame'); + viewDiffFrame.src = + 'attachment.cgi?id=' + attachment_id + '&action=diff&headers=0'; + has_viewed_as_diff = 1; + } +} + +function viewRaw(patchviewerinstalled) +{ + switchToMode('raw', patchviewerinstalled); +} + +function switchToMode(mode, patchviewerinstalled) +{ + if (mode == current_mode) { + alert('switched to same mode! This should not happen.'); + return; + } + + // Switch out of current mode + if (current_mode == 'edit') { + hideElementById('editFrame'); + hideElementById('undoEditButton'); + } else if (current_mode == 'raw') { + hideElementById('viewFrame'); + if (patchviewerinstalled) + hideElementById('viewDiffButton'); + hideElementById(has_edited ? 'redoEditButton' : 'editButton'); + hideElementById('smallCommentFrame'); + } else if (current_mode == 'diff') { + if (patchviewerinstalled) + hideElementById('viewDiffFrame'); + hideElementById('viewRawButton'); + hideElementById(has_edited ? 'redoEditButton' : 'editButton'); + hideElementById('smallCommentFrame'); + } + + // Switch into new mode + if (mode == 'edit') { + showElementById('editFrame'); + showElementById('undoEditButton'); + } else if (mode == 'raw') { + showElementById('viewFrame'); + if (patchviewerinstalled) + showElementById('viewDiffButton'); + + showElementById(has_edited ? 'redoEditButton' : 'editButton'); + showElementById('smallCommentFrame'); + } else if (mode == 'diff') { + if (patchviewerinstalled) + showElementById('viewDiffFrame'); + + showElementById('viewRawButton'); + showElementById(has_edited ? 'redoEditButton' : 'editButton'); + showElementById('smallCommentFrame'); + } + + prev_mode = current_mode; + current_mode = mode; +} + +function hideElementById(id) +{ + var elm = document.getElementById(id); + if (elm) { + elm.style.display = 'none'; + } +} + +function showElementById(id, val) +{ + var elm = document.getElementById(id); + if (elm) { + if (!val) val = 'inline'; + elm.style.display = val; + } +} + +function normalizeComments() +{ + // Remove the unused comment field from the document so its contents + // do not get transmitted back to the server. + + var small = document.getElementById('smallCommentFrame'); + var big = document.getElementById('editFrame'); + if ( (small) && (small.style.display == 'none') ) + { + small.parentNode.removeChild(small); + } + if ( (big) && (big.style.display == 'none') ) + { + big.parentNode.removeChild(big); + } +} diff --git a/template/en/default/attachment/edit.html.tmpl b/template/en/default/attachment/edit.html.tmpl index 95c90871f..db92d18d3 100644 --- a/template/en/default/attachment/edit.html.tmpl +++ b/template/en/default/attachment/edit.html.tmpl @@ -36,136 +36,12 @@ header = header subheader = subheader doc_section = "attachments.html" + javascript_urls = ['js/attachment.js']; %] [%# No need to display the Diff button and iframe if the attachment is not a patch. %] [% patchviewerinstalled = (patchviewerinstalled && attachment.ispatch) %] -<script type="text/javascript"> - <!-- - var prev_mode = 'raw'; - var current_mode = 'raw'; - var has_edited = 0; - var has_viewed_as_diff = 0; - function editAsComment() - { - switchToMode('edit'); - has_edited = 1; - } - function undoEditAsComment() - { - switchToMode(prev_mode); - } - function redoEditAsComment() - { - switchToMode('edit'); - } -[% IF patchviewerinstalled %] - function viewDiff() - { - switchToMode('diff'); - - // If we have not viewed as diff before, set the view diff frame URL - if (!has_viewed_as_diff) { - var viewDiffFrame = document.getElementById('viewDiffFrame'); - viewDiffFrame.src = - 'attachment.cgi?id=[% attachment.id %]&action=diff&headers=0'; - has_viewed_as_diff = 1; - } - } -[% END %] - function viewRaw() - { - switchToMode('raw'); - } - - function switchToMode(mode) - { - if (mode == current_mode) { - alert('switched to same mode! This should not happen.'); - return; - } - - // Switch out of current mode - if (current_mode == 'edit') { - hideElementById('editFrame'); - hideElementById('undoEditButton'); - } else if (current_mode == 'raw') { - hideElementById('viewFrame'); -[% IF patchviewerinstalled %] - hideElementById('viewDiffButton'); -[% END %] - hideElementById(has_edited ? 'redoEditButton' : 'editButton'); - hideElementById('smallCommentFrame'); - } else if (current_mode == 'diff') { -[% IF patchviewerinstalled %] - hideElementById('viewDiffFrame'); -[% END %] - hideElementById('viewRawButton'); - hideElementById(has_edited ? 'redoEditButton' : 'editButton'); - hideElementById('smallCommentFrame'); - } - - // Switch into new mode - if (mode == 'edit') { - showElementById('editFrame'); - showElementById('undoEditButton'); - } else if (mode == 'raw') { - showElementById('viewFrame'); -[% IF patchviewerinstalled %] - showElementById('viewDiffButton'); -[% END %] - showElementById(has_edited ? 'redoEditButton' : 'editButton'); - showElementById('smallCommentFrame'); - } else if (mode == 'diff') { -[% IF patchviewerinstalled %] - showElementById('viewDiffFrame'); -[% END %] - showElementById('viewRawButton'); - showElementById(has_edited ? 'redoEditButton' : 'editButton'); - showElementById('smallCommentFrame'); - } - - prev_mode = current_mode; - current_mode = mode; - } - - function hideElementById(id) - { - var elm = document.getElementById(id); - if (elm) { - elm.style.display = 'none'; - } - } - - function showElementById(id, val) - { - var elm = document.getElementById(id); - if (elm) { - if (!val) val = 'inline'; - elm.style.display = val; - } - } - - function normalizeComments() - { - // Remove the unused comment field from the document so its contents - // do not get transmitted back to the server. - - var small = document.getElementById('smallCommentFrame'); - var big = document.getElementById('editFrame'); - if ( (small) && (small.style.display == 'none') ) - { - small.parentNode.removeChild(small); - } - if ( (big) && (big.style.display == 'none') ) - { - big.parentNode.removeChild(big); - } - } - //--> -</script> - <form method="post" action="attachment.cgi" onsubmit="normalizeComments();"> <input type="hidden" name="id" value="[% attachment.id %]"> <input type="hidden" name="action" value="update"> @@ -301,17 +177,20 @@ </iframe> <script type="text/javascript"> <!-- + var patchviewerinstalled = 0; + var attachment_id = [% attachment.id %]; if (typeof document.getElementById == "function") { [% IF patchviewerinstalled %] + var patchviewerinstalled = 1; document.write('<iframe id="viewDiffFrame" style="height: 400px; width: 100%; display: none;"><\/iframe>'); [% END %] - document.write('<button type="button" id="editButton" onclick="editAsComment();">Edit Attachment As Comment<\/button>'); - document.write('<button type="button" id="undoEditButton" onclick="undoEditAsComment();" style="display: none;">Undo Edit As Comment<\/button>'); - document.write('<button type="button" id="redoEditButton" onclick="redoEditAsComment();" style="display: none;">Redo Edit As Comment<\/button>'); + document.write('<button type="button" id="editButton" onclick="editAsComment(patchviewerinstalled);">Edit Attachment As Comment<\/button>'); + document.write('<button type="button" id="undoEditButton" onclick="undoEditAsComment(patchviewerinstalled);" style="display: none;">Undo Edit As Comment<\/button>'); + document.write('<button type="button" id="redoEditButton" onclick="redoEditAsComment(patchviewerinstalled);" style="display: none;">Redo Edit As Comment<\/button>'); [% IF patchviewerinstalled %] - document.write('<button type="button" id="viewDiffButton" onclick="viewDiff();">View Attachment As Diff<\/button>'); + document.write('<button type="button" id="viewDiffButton" onclick="viewDiff(attachment_id, patchviewerinstalled);">View Attachment As Diff<\/button>'); [% END %] - document.write('<button type="button" id="viewRawButton" onclick="viewRaw();" style="display: none;">View Attachment As Raw<\/button>'); + document.write('<button type="button" id="viewRawButton" onclick="viewRaw(patchviewerinstalled);" style="display: none;">View Attachment As Raw<\/button>'); } //--> </script> |