summaryrefslogtreecommitdiffstats
path: root/template/default/attachment/edit.atml
blob: ac9f327d032f06c646e46403750e9babca9acbe7 (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
[%# Define strings that will serve as the title and header of this page %]
[% title = BLOCK %]Edit Attachment #[% attachid %] for Bug #[% bugid %][% END %]
[% h1 = BLOCK %]Edit Attachment #[% attachid %] for <a href="show_bug.cgi?id=[% bugid %]">Bug #[% bugid %]</a>[% END %]
[% h2 = BLOCK %][% bugsummary FILTER html %][% END %]

[% INCLUDE global/header 
  title = title
  h1 = h1
  h2 = h2
  style = "
    th { text-align: right; vertical-align: top; }
    td { text-align: left; vertical-align: top; }
    td#info { text-align: right; vertical-align: top; }
    td#actions { text-align: right; vertical-align: bottom; }
    td#noview { text-align: left; vertical-align: center; }
  "
%]

<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 width="100%">

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

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

        <b>Flags:</b><br>
          <input type="checkbox" name="ispatch" value="1"[% " checked" IF ispatch %]>patch
          <input type="checkbox" name="isobsolete" value="1"[% " checked" IF isobsolete %]>obsolete<br>

        [% IF statusdefs.size %]
          <b>Status:</b><br>
            [% FOREACH def = statusdefs %]
                <input type="checkbox" name="status" value="[% def.id %]"[% " checked" IF statuses.${def.id} %]>[% def.name %]<br>
            [% END %]
        [% END %]

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

        <input type="submit" value="Submit">

        </small>
      </td>

      [% IF isviewable %]
        <td width="75%">
          <textarea id="editFrame" name="comment" style="height: 400px; width: 100%; display: none;"></textarea>
          <iframe id="viewFrame" src="attachment.cgi?id=[% attachid %]&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 %]&action=view">View the attachment on a separate page</a>.</b>
          </iframe>
          <button id="editButton" onclick="editAsComment();">Edit Attachment As Comment</button>
          <button id="undoEditButton" onclick="undoEditAsComment();" style="display: none;">Undo Edit As Comment</button>
          <button id="redoEditButton" onclick="redoEditAsComment();" style="display: none;">Redo Edit As Comment</button>
        </td>
      [% ELSE %]
        <td id="noview" width="50%">
          <p><b>
            Attachment cannot be viewed because its MIME type is not either text/*, image/*, or application/vnd.mozilla.*.
            <a href="attachment.cgi?id=[% attachid %]&action=view">Download the attachment instead</a>.
          </b></p>
        </td>
      [% END %]

    </tr>

  </table>

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

</form>

<script type="application/x-javascript" language="JavaScript">
  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 %]';
      if ( contentType == 'text/plain' )
        {
          theContent = theContent.replace( /^<html><head\/><body><pre>/ , "" );
          theContent = theContent.replace( /<\/pre><\/body><\/html>$/ , "" );
          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" );

      hideElementById('viewFrame');
      hideElementById('editButton');
      hideElementById('smallCommentFrame');

      showElementById('undoEditButton');

      // Show the TEXTAREA that will contain the editable attachment
      // and copy the content of the attachment into it.
      showElementById('editFrame');

      var editFrame = document.getElementById('editFrame');
      editFrame.value = theContent;
      editFrame.value += "\n\n";
    }
  function undoEditAsComment()
    {
      // Hide the "edit attachment as comment" TEXTAREA and the "undo" button.
      hideElementById('undoEditButton');
      hideElementById('editFrame');

      // Show the "view attachment" IFRAME, the "redo" button that allows the user
      // to go back to editing the attachment as a comment, and the small comment field.
      showElementById('viewFrame');
      showElementById('redoEditButton');
      showElementById('smallCommentFrame');

    }
  function redoEditAsComment()
    {
      // Hide the "view attachment" IFRAME, the "redo" button that allows the user
      // to go back to editing the attachment as a comment, and the small comment field.
      hideElementById('viewFrame');
      hideElementById('redoEditButton');
      hideElementById('smallCommentFrame');

      // Show the "edit attachment as comment" TEXTAREA and the "undo" button.
      showElementById('undoEditButton');
      showElementById('editFrame');
    }

  function hideElementById(id)
  {
    var elm = document.getElementById(id);
    if (!elm) return;

    elm.style.setProperty('display', 'none', '');
  }

  function showElementById(id, val)
  {
    var elm = document.getElementById(id);
    if (!elm) return;

    if (!val) val = 'inline';
    elm.style.setProperty('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.getProperty('display') == 'none' )
    {
      small.parentNode.removeChild(small);
    }
    if ( big.style.getProperty('display') == 'none' )
    {
      big.parentNode.removeChild(big);
    }
    
  }
</script>

<br>

[% INCLUDE global/footer %]