[%# 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): Chris Lahey <clahey@ximian.com> [javascript fixes]
  #                 Christian Reis <kiko@async.com.br> [javascript rewrite]
  #                 Gervase Markham <gerv@gerv.net>
  #%]

[% USE Bugzilla %]

<script type="text/javascript" src="js/query-visibility.js"></script>
<script type="text/javascript" src="js/field.js"></script>
<script type="text/javascript" src="fieldvaluecontrol.cgi?type=search&user=[% Bugzilla.user.id %]"></script>

<script type="text/javascript">

var first_load = true;         [%# is this the first time we load the page? %]
var last_sel = new Array();    [%# caches last selection %]
var useclassification = [% Param('useclassification') ? 'true' : 'false' %];

addListener(window, 'load', function()
{
  var lim = 250;
  function checkw(e)
  {
    var s = document.getElementById(e);
    s.style.minWidth = '100%';
    if (s && s.offsetWidth > lim)
    {
      s.style.width = lim+'px';
      addListener(s, 'mouseover', function(e)
      {
        e = e || window.event;
        var f = e.relatedTarget || e.fromElement;
        if (f == s || f.parentNode == s || !s.style.width && s.offsetWidth <= lim)
          return;
        var c = s;
        while (c && c.nodeName != 'TABLE')
          c = c.parentNode;
        [%# FIXME: Удалить вторую таблицу внутри каждой ячейки! Она там нах* не нужна! %]
        c = c.parentNode;
        while (c && c.nodeName != 'TABLE')
          c = c.parentNode;
        var w = (lim+c.parentNode.offsetWidth-c.offsetWidth);
        if (w > lim+10)
        {
          s.style.width = '';
          s.style.maxWidth = w + 'px';
        }
      });
      addListener(s, 'mouseout', function(e) {
        e = e || window.event;
        var t = e.relatedTarget || e.toElement;
        if (t == s || t.parentNode == s)
          return;
        s.style.width = lim+'px';
        s.style.maxWidth = '';
      });
    }
  }
  for (var i in checkwidths)
    checkw(checkwidths[i]);
});

</script>

[% SET checkwidths = [] %]

[%# If we resubmit to ourselves, we need to know if we are using a format. %]
[% thisformat = query_format != '' ? query_format : format %]
<input type="hidden" name="query_format" value="[% thisformat FILTER html %]">

[%# *** Summary *** %]

<table>
  <tr>
    <th align="right" colspan="2">
      <label for="content">Words (full-text search):</label>
    </th>
    <td>
      <input name="content" size="40" id="content"
             value="[% default.content.0 FILTER html %]">
      <script type="text/javascript"> <!--
          document.forms[queryform].content.focus();
      // -->
      </script>
    </td>
  </tr>

  <tr>
    <th align="right">
      <label for="short_desc" accesskey="s"><u>S</u>ummary</label>:
    </th>
    <td>[% html_select('short_desc_type', default.short_desc_type.0, text_types, lc_messages.operator_descs) %]</td>
    <td>
      <input name="short_desc" id="short_desc" size="40"
             value="[% default.short_desc.0 FILTER html %]">
      <script type="text/javascript"> <!--
          document.forms[queryform].short_desc.focus();
      // -->
      </script>
    </td>
    <td>
      [% IF button_name %]
        <input type="submit" id="[% button_name FILTER css_class_quote %]_top"
               value="[% button_name FILTER html %]">
      [% END %]
    </td>
  </tr>
</table>

[%# *** Classification Product Component Version Target *** %]
<table>
  <tr>
  [% Hook.process('before_selects_top') %]
  [% IF Param('useclassification') %]
    <td valign="top" id="classification_cont">
      <table>
        <tr valign="bottom">
          <th align="left">
            <label for="classification">Classification</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'classification', size => 5 } %]
        </tr>
      </table>
    </td>
  [% END %]
    <td valign="top" id="product_cont">
      <table>
        <tr valign="bottom">
          <th align="left">
            <label for="product" accesskey="p"><u>P</u>roduct</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'product', size => 5 } %]
        </tr>
      </table>
    </td>
    <td valign="top" id="component_cont">
      <table>
        <tr valign="bottom">
          <th align="left">
            <label for="component" accesskey="m"><a href="describecomponents.cgi">Co<u>m</u>ponent</a></label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'component', size => 5 } %]
        </tr>
      </table>
    </td>
    <td valign="top" id="version_cont">
      <table>
        <tr valign="bottom">
          <th align="left">
            <label for="version">Version</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'version',
                                    size => 5 } %]
        </tr>
      </table>
    </td>
  [% IF Param('usetargetmilestone') %]
    <td valign="top" id="target_milestone_cont">
      <table>
        <tr valign="bottom">
          <th align="left">
            <label for="target_milestone">Target</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'target_milestone',
                                    size => 5 } %]
        </tr>
      </table>
    </td>
  [% END %]
  [% Hook.process('after_selects_top') %]
  </tr>
</table>

[%# *** Custom select fields *** %]
[% IF Bugzilla.get_fields({ is_select => 1, obsolete => 0, custom => 1 }).size %]
<table>
  <tr>
  [% i = 0 %]
  [% FOR f = Bugzilla.get_fields({ is_select => 1, obsolete => 0, custom => 1, sort => 1 }) %]
    [% IF f.legal_value_names.size %]
      [% IF i AND !(i % 4) %]
  </tr>
</table>
<table>
  <tr>
      [% END %]
      <td valign="top" id="[% f.name | html %]_cont">
        <table>
          <tr valign="bottom">
            <th align="left">
              <label for="[% f.name | html %]">[% f.description | html %]</label>:
            </th>
          </tr>
          <tr valign="top">
            [% PROCESS select sel = { name => f.name, size => 5 } %]
          </tr>
        </table>
      </td>
      [% i = i+1 %]
    [% END %]
  [% END %]
  </tr>
</table>
[% END %]

[%# *** Comment URL Whiteboard Keywords *** %]
<table>
  [% tf_desc = {
       longdesc          => "A&nbsp;<u>C</u>omment",
       bug_file_loc      => "The&nbsp;<u>U</u>RL",
       status_whiteboard => "<u>W</u>hiteboard",
  } %]
  [% tf_accesskey = {
       longdesc          => 'c',
       bug_file_loc      => 'u',
       status_whiteboard => 'w',
  } %]

  [% Hook.process('before_freetext_fields') %]

  [% FOREACH field = freetext_fields %]
    <tr id="[% field.name %]_cont">
      <th align="right">
        <label for="[% field.name %]"
               accesskey="[% tf_accesskey.${field.name} %]">[% tf_desc.${field.name} || field.description %]</label>:
      </th>
      <td>
        [% t = field.name _ '_type' %]
        [% html_select(t, default.$t.0, text_types, lc_messages.operator_descs) %]
      </td>
      <td>
        <input name="[% field.name %]" id="[% field.name %]" size="40"
          value="[% default.${field.name}.0 FILTER html %]" />
      </td>
      <td></td>
    </tr>
  [% END %]

  [% IF use_keywords %]
    <tr>
      <th align="right">
        <label for="keywords" accesskey="k"><a href="describekeywords.cgi"><u>K</u>eywords</a></label>:
      </th>
      <td>
        [% keywords_types = ['allwords', 'anywords', 'nowords', 'regexp', 'notregexp'] %]
        [% html_select('keywords_type', default.keywords_type.0, keywords_types, lc_messages.operator_descs) %]
      </td>
      <td>
        <input name="keywords" id="keywords" size="40"
               value="[% default.keywords.0 FILTER html %]">
        <script type="text/javascript">
        addListener(window, 'load', function() {
            var emptyOptions = [% keyword_list ? json(keyword_list) : "null" %];
            new SimpleAutocomplete("keywords",
                function(h) { keywordAutocomplete(h, emptyOptions); },
                { emptyText: 'No keywords found', multipleDelimiter: "," }
            );
        }); 
        </script>

      </td>
    </tr>
  [% END %]

  [%# Deadline %]
  [% IF user.is_timetracker %]
    <tr>
      <th align="right">
        <label for="deadlinefrom" accesskey="l">Dead<u>l</u>ine</label>:
      </th>
      <td>
        from <input name="deadlinefrom" id="deadlinefrom" size="10" maxlength="10"
                    value="[% default.deadlinefrom.0 FILTER html %]">
        to <input name="deadlineto" id="deadlineto" size="10" maxlength="10"
                  value="[% default.deadlineto.0 FILTER html %]">
        <script type="text/javascript">
           Calendar.set('deadlinefrom');
           Calendar.set('deadlineto');
        </script>
      </td>
      <td>
        <small>(YYYY-MM-DD or relative dates)</small>
      </td>
    </tr>
  [% END %]

  [% Hook.process('after_freetext_fields') %]

</table>

<hr>

[%# *** Status Resolution Severity Priority Hardware OS *** %]

<table>
  <tr>
    [% Hook.process('before_selects_bottom') %]
    <td>
      <table>
        <tr>
          <th align="left">
            <label for="bug_status" accesskey="a">St<u>a</u>tus</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'bug_status',
                                    size => 7 } %]
        </tr>
      </table>
    </td>
    <td>
      <table>
        <tr>
          <th align="left">
            <label for="resolution" accesskey="r"><u>R</u>esolution</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'resolution',
                                    size => 7 } %]
        </tr>
      </table>
    </td>
    <td>
      <table>
        <tr>
          <th align="left">
            <label for="bug_severity">Severity</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'bug_severity',
                                    size => 7 }%]
        </tr>
      </table>
    </td>
    <td>
      <table>
        <tr>
          <th align="left">
            <label for="priority" accesskey="i">Pr<u>i</u>ority</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'priority',
                                    size => 7 } %]
        </tr>
      </table>
    </td>
    [% IF Param('useplatform') %]
    <td>
      <table>
        <tr>
          <th align="left">
            <label for="rep_platform" accesskey="h"><u>H</u>ardware</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'rep_platform',
                                    size => 7 } %]
        </tr>
      </table>
    </td>
    [% END %]
    [% IF Param('useopsys') %]
    <td>
      <table>
        <tr>
          <th align="left">
            <label for="op_sys" accesskey="o"><u>O</u>S</label>:
          </th>
        </tr>
        <tr valign="top">
          [% PROCESS select sel = { name => 'op_sys',
                                    size => 7 } %]
        </tr>
      </table>
    </td>
    [% END %]
    [% Hook.process('after_selects_bottom') %]
  </tr>
</table>

[%# *** Email Numbering Votes *** %]

<table>
  <tr>
    <td style="vertical-align: top">
      <fieldset>
        <legend>
          <strong>
            [% IF Param('usevotes') %]
              Email Addresses, [% terms.Bug %] Numbers, and Votes
            [% ELSE %]
              Email Addresses and [% terms.Bug %] Numbers
            [% END %]
          </strong>
        </legend>


<table>
  <tr>
  [% FOREACH n = [1, 2] %]
    <td>

<table cellspacing="0" cellpadding="0">
  <tr>
    <td>
      Any of:
    </td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" name="emailassigned_to[% n %]"
             id="emailassigned_to[% n %]" value="1"
             [% " checked" IF default.emailassigned_to.$n %] />
      <label for="emailassigned_to[% n %]">
        the [% terms.bug %] assignee
      </label>
    </td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" name="emailreporter[% n %]"
             id="emailreporter[% n %]" value="1"
             [% " checked" IF default.emailreporter.$n %] />
      <label for="emailreporter[% n %]">
        the reporter
      </label>
    </td>
  </tr>
  [% IF Param('useqacontact') %]
  <tr>
    <td>
      <input type="checkbox" name="emailqa_contact[% n %]"
             id="emailqa_contact[% n %]" value="1"
             [% " checked" IF default.emailqa_contact.$n %] />
      <label for="emailqa_contact[% n %]">
        the QA contact
      </label>
    </td>
  </tr>
  [% END %]
  <tr>
    <td>
      <input type="checkbox" name="emailcc[% n %]"
             id="emailcc[% n %]" value="1"
             [% " checked" IF default.emailcc.$n %] />
      <label for="emailcc[% n %]">
        a CC list member
      </label>
    </td>
  </tr>
  <tr>
    <td>
        <input type="checkbox" name="emaillongdesc[% n %]"
               id="emaillongdesc[% n %]" value="1"
               [% " checked" IF default.emaillongdesc.$n %] />
      <label for="emaillongdesc[% n %]">
        a commenter
      </label>
    </td>
  </tr>
  <tr>
    <td>
      [% html_select('emailtype' _ n, default.emailtype.$n, [
           { id => "exact",     name => "is" },
           { id => "substring", name => "contains" },
           { id => "notequals", name => "is not" },
           { id => "regexp",    name => "matches regexp" },
           { id => "notregexp", name => "doesn't match regexp" }
         ]) %]
    </td>
  </tr>
  <tr>
    <td>
      <input id="email[% n %]" name="email[% n %]"
        size="25" value="[% default.email.$n FILTER html %]"
        autocomplete="off" />
    </td>
  </tr>
</table>

    </td>
    <script language="JavaScript">
    addListener(window, 'load', function() {
      new SimpleAutocomplete("email[% n %]", userAutocomplete, { emptyText: 'No users found' });
    });
    </script>
  [% END %]
  </tr>
</table>
<hr />
<table>
  <tr>
    <td>
      <select name="bug_id_type">
        <option value="anyexact"[% " selected" IF default.bug_id_type.0 == "anyexact" %]>Only include</option>
        <option value="nowords"[% " selected" IF default.bug_id_type.0 == "nowords" %]>Exclude</option>
      </select>
      <label for="bug_id">[% terms.bugs %] numbered</label>:
    </td>
    <td>
      <input type="text" name="bug_id" id="bug_id"
             value="[% default.bug_id.0 FILTER html %]" size="20">
    </td>
  </tr>
  <tr>
    <td></td>
    <td>(comma-separated list)</td>
  </tr>
  [% IF Param('usevotes') %]
    <tr>
      <td align="right">
        <label for="votes">Only [% terms.bugs %] with at least</label>:
      </td>
      <td>
        <input name="votes" id="votes" size="3" value="[% default.votes.0 FILTER html %]" />
        votes
      </td>
    </tr>
  [% END %]
</table>

      </fieldset>
    </td>

[%# *** Bug Changes *** %]

    <td style="vertical-align: top">
      <fieldset>
        <legend><strong>[% terms.Bug %] Changes</strong></legend>

<dl class="bug_changes">
  <dt>
    <label for="chfieldfrom">Only [% terms.bugs %] changed between</label>:
  </dt>
  <dd>
    <input name="chfieldfrom" id="chfieldfrom"
           size="10" value="[% default.chfieldfrom.0 FILTER html %]" />
    and <input name="chfieldto" id="chfieldto" size="10" value="[% default.chfieldto.0 FILTER html %]" />
    <br />(YYYY-MM-DD or relative dates)
        <script type="text/javascript">
           Calendar.set('chfieldfrom');
           Calendar.set('chfieldto');
        </script>
  </dd>
  <dt><label for="chfieldwho">By user:</label></dt>
  <dd><input name="chfieldwho" id="chfieldwho" size="20" value="[% default.chfieldwho.0 | html %]" /> (user login)</dd>
  <dt><label for="chfield">where one or more of the following changed</label>:</dt>
  <dd>[% html_select('chfield', default.chfield, chfield, '', { multiple => 'multiple' }) %]</dd>
  <dt>and <label for="chfieldvalue">the new value was</label>:</dt>
  <dd>
    <input name="chfieldvalue" id="chfieldvalue"
           size="20" value="[% default.chfieldvalue.0 FILTER html %]">
  </dd>
</dl>
<script language="JavaScript">
addListener(window, 'load', function() {
  new SimpleAutocomplete("chfieldwho", userAutocomplete, { emptyText: 'No users found' });
});
</script>

       </fieldset>
     </td>
  </tr>
</table>

[%############################################################################%]
[%# Block for SELECT fields                                                  #%]
[%############################################################################%]

[% BLOCK select %]
  <td align="left">
    <select name="[% sel.name | html %]" id="[% sel.name | html %]"
            multiple="multiple" size="[% sel.size %]">
      [% FOREACH value = Bugzilla.get_field(sel.name).legal_value_names %]
        <option value="[% value.name OR '---' FILTER html %]" id="qf_[% sel.name | html %]_[% value.ids.join('_') %]"
          [% " selected" IF lsearch(default.${sel.name}, value.name) != -1 %]>
          [% value.name FILTER html
        %]</option>
      [% END %]
    </select>
    [% checkwidths.push(sel.name) %]
  </td>
[% END %]

<script type="text/javascript">
var checkwidths = [% json(checkwidths) %];
</script>
