summaryrefslogtreecommitdiffstats
path: root/template/en/default/attachment/edit.html.tmpl
blob: a05945df0893b4136069a51faa3dad3de9237ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
[%# 1.0@bugzilla.org %]
[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Myk Melez <myk@mozilla.org>
  #%]

[% PROCESS global/variables.none.tmpl %]

[%# Define strings that will serve as the title and header of this page %]
[% title = BLOCK %]Edit Attachment #[% attachid %] for [% terms.Bug %] #[% bugid %][% END %]
[% h1 = BLOCK %]Edit Attachment #[% attachid %] for
  [%+ GetBugLink(bugid, "$terms.Bug $bugid") %][% END %]
[% h2 = BLOCK %][% bugsummary FILTER html %][% END %]

[% PROCESS global/header.html.tmpl
  title = title
  h1 = h1
  h2 = h2
  style = "
    table.attachment_info th { text-align: right; vertical-align: top; }
    table.attachment_info td { text-align: left; vertical-align: top; }
    #noview { text-align: left; vertical-align: center; }

    table#flags th, table#flags td { font-size: small; vertical-align: baseline; text-align: left; }
  "
%]

<script type="application/x-javascript" language="JavaScript">
  <!--
  var prev_mode = 'raw';
  var current_mode = 'raw';
  var has_edited = 0;
  var has_viewed_as_diff = 0;
  function editAsComment()
    {
      // Get the content of the document as a string.
      var viewFrame = document.getElementById('viewFrame');
      var aSerializer = new XMLSerializer();
      var contentDocument = viewFrame.contentDocument;
      var theContent = aSerializer.serializeToString(contentDocument);

      // If this is a plaintext document, remove cruft that Mozilla adds
      // because it treats it as an HTML document with a big PRE section.
      // http://bugzilla.mozilla.org/show_bug.cgi?id=86012
      var contentType = '[% contenttype FILTER js %]';
      if ( contentType == 'text/plain' )
        {
          theContent = theContent.replace( /^<html><head\/?><body><pre>/i , "" );
          theContent = theContent.replace( /<\/pre><\/body><\/html>$/i , "" );
          theContent = theContent.replace( /&lt;/gi , "<" );
          theContent = theContent.replace( /&gt;/gi , ">" );
          theContent = theContent.replace( /&amp;/gi , "&" );
        }

      // Add mail-style quote indicators (>) to the beginning of each line.
      // ".*\n" matches lines that end with a newline, while ".+" matches
      // the rare situation in which the last line of a file does not end
      // with a newline.
      theContent = theContent.replace( /(.*\n|.+)/g , ">$1" );

      switchToMode('edit');

      // Copy the contents of the diff into the textarea
      var editFrame = document.getElementById('editFrame');
      editFrame.value = theContent;
      editFrame.value += "\n\n";

      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=[% attachid %]&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.style.display == 'none' )
    {
      small.parentNode.removeChild(small);
    }
    if ( big.style.display == 'none' )
    {
      big.parentNode.removeChild(big);
    }
  }
  //-->
</script>

<form method="post" action="attachment.cgi" onsubmit="normalizeComments();">
  <input type="hidden" name="id" value="[% attachid %]">
  <input type="hidden" name="action" value="update">
  <input type="hidden" name="contenttypemethod" value="manual">

  <table class="attachment_info" width="100%">

    <tr>
      <td width="25%">
        <small>
        <b>Description:</b><br>
          <textarea rows="3" cols="25" name="description" wrap="soft">[% description FILTER html %]</textarea><br>

        <b>Filename:</b><br>
          <input type="text" size="20" name="filename" value="[% filename FILTER html %]"><br>
        <b>Size: </b>[% datasize FILTER unitconvert %]<br>

        <b>MIME Type:</b><br>
          <input type="text" size="20" name="contenttypeentry" value="[% contenttype FILTER html %]"><br>

          <input type="checkbox" id="ispatch" name="ispatch" value="1"
                 [% 'checked="checked"' IF ispatch %]>
          <label for="ispatch">patch</label>
          <input type="checkbox" id="isobsolete" name="isobsolete" value="1"
                 [% 'checked="checked"' IF isobsolete %]>
          <label for="isobsolete">obsolete</label><br>
          [% IF (Param("insidergroup") && UserInGroup(Param("insidergroup"))) %]
            <input type="checkbox" name="isprivate" value="1"[% " checked" IF isprivate %]> private<br><br>
          [% ELSE %]<br>
          [% END %]

        [% IF flag_types.size > 0 %]
          [% PROCESS "flag/list.html.tmpl" bug_id=bugid attach_id=attachid %]<br>
        [% END %]

        <div id="smallCommentFrame">
          <b>Comment (on the [% terms.bug %]):</b><br>
            <textarea name="comment" rows="5" cols="25" wrap="soft"></textarea><br>
        </div>

        <input type="submit" value="Submit"><br><br>
        <strong>Actions:</strong> <a href="attachment.cgi?id=[% attachid %]">View</a>
        [% IF ispatch && patchviewerinstalled %]
         | <a href="attachment.cgi?id=[% attachid %]&action=diff">Diff</a>
        [% END %]
        </small>
      </td>

      [% IF isviewable %]
        <td width="75%">
          <textarea id="editFrame" name="comment" style="height: 400px; width: 100%; display: none;" cols="80" wrap="soft"></textarea>
          <iframe id="viewFrame" src="attachment.cgi?id=[% attachid %]&amp;action=view" style="height: 400px; width: 100%;">
            <b>You cannot view the attachment while editing it because your browser does not support IFRAMEs.
            <a href="attachment.cgi?id=[% attachid %]&amp;action=view">View the attachment on a separate page</a>.</b>
          </iframe>
          <script type="application/x-javascript" language="JavaScript">
            <!--
            if (typeof document.getElementById == "function") {
[% IF patchviewerinstalled %]
              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>');
[% IF patchviewerinstalled %]
              document.write('<button type="button" id="viewDiffButton" onclick="viewDiff();">View Attachment As Diff</button>');
[% END %]
              document.write('<button type="button" id="viewRawButton" onclick="viewRaw();" style="display: none;">View Attachment As Raw</button>');
            }
            //-->
          </script>
        </td>
      [% ELSE %]
        <td id="noview" width="50%">
          <p><b>
            Attachment is not viewable in your browser because its MIME type 
            ([% contenttype FILTER html %]) is not one that your browser is 
            able to display.
          </b></p>
          <p><b>
            <a href="attachment.cgi?id=[% attachid %]&amp;action=view">Download
            the attachment</a>.
          </b></p>
        </td>
      [% END %]

    </tr>

  </table>

  Attachments on this [% terms.Bug %]:
  [% FOREACH a = attachments %]
    [% IF a == attachid %]
      #[% a %]
    [% ELSE %]
      <a href="attachment.cgi?id=[% a %]&amp;action=edit">#[% a %]</a>
    [% END %]
    [% " |" UNLESS loop.last() %]
  [% END %]

</form>

<br>

[% PROCESS global/footer.html.tmpl %]