<metal:search define-macro="search">
  <div id="search"
       tal:define="macros item/template/macros;
                   idPrefix string:${view/itemNum}.search;
                   formId string:$idPrefix.form;
                   resultsId string:$idPrefix.results">
    <h1 tal:attributes="class string:content-$level;
                        ondblclick item/openEditWindow"
      tal:content="item/title">
      Search
    </h1>

    <div metal:define-macro="search_form" class="searchForm">
      <fieldset class="box">
        <form action="." method="post" id="1.search.form"
              tal:attributes="id formId">
          <input type="hidden" name="search.submitted" value="yes" />
          <input type="hidden" name="search.resultsId" value="1.results"
                 tal:attributes="value resultsId" />
          <table cellpadding="3">
            <tal:block repeat="search_param python: ['type', 'text', 'concept']">
              <metal:row use-macro="macros/search_row" />
            </tal:block>
            <tr tal:condition="nothing">
              <td colspan="2">
                <input type="button" value="Add concept filter" class="button" />
                <input type="button" value="Add attribute filter" class="button" />
              </td>
            </tr>
            <tr>
              <td></td>
              <td colspan="3">
                <input type="submit" name="button.search" value="Search" class="submit"
                       i18n:attributes="value"
                       tal:attributes="onclick python:
                                item.submitReplacing(resultsId, formId, view)" />
              </td>
            </tr>
          </table>
        </form>
      </fieldset>
    </div>

    <div metal:define-macro="search_results" id="1.search.results"
         tal:attributes="id resultsId | request/search.resultsId"
         i18n:domain="loops">
      <fieldset class="box"
                tal:condition="request/search.submitted | nothing">
        <h2 i18n:translate="">Search results</h2>
        <table class="listing" summary="Search results"
               i18n:attributes="summary">
          <thead>
            <tr>
              <th i18n:translate="">Title</th>
              <th i18n:translate="">Type</th>
              <th i18n:translate=""
                  tal:condition="view/useVersioning">V</th>
              <th i18n:translate="">Size</th>
              <th i18n:translate="">Modification Date</th>
              <th i18n:translate="">Author(s)</th>
            </tr>
          </thead>
          <tbody>
            <tal:items tal:repeat="row view/results">
              <tal:item define="class python: repeat['row'].odd() and 'even' or 'odd';
                                description row/description">
                <tr tal:attributes="class class">
                  <td>
                    <a tal:attributes="href string:${view/url}/.target${row/uniqueId}?version=this;
                                       title description"
                       tal:content="row/title" />
                  </td>
                  <td i18n:translate=""
                      tal:content="row/longTypeTitle|row/typeTitle">Type</td>
                  <tal:version condition="view/useVersioning">
                    <td style="text-align: center"
                        tal:define="versionId row/versionId|string:">
                      <a href="#"
                         tal:content="versionId"
                         tal:omit-tag="python: versionId and versionId=='1.1'"
                         tal:attributes="href string:${view/url}/.target${row/uniqueId}?loops.viewName=listversions">1.1</a>
                    </td>
                  </tal:version>
                  <td style="text-align: right; white-space: nowrap">
                    <span tal:replace="row/context/sizeForDisplay|string:">Size</span>
                  </td>
                  <td><span tal:replace="row/modified">modified</span></td>
                  <td><span tal:replace="row/creators">John</span></td>
                </tr>
              </tal:item>
            </tal:items>
          </tbody>
        </table>
      </fieldset>
    </div>

  </div>
</metal:search>


<div metal:define-macro="search_row" id="1.1.row"
           tal:define="rowNum item/rowNum;
                       basicIdPrefix idPrefix;
                       idPrefix string:$idPrefix.$rowNum;
                       namePrefix string:search.$rowNum;
                       param search_param | item/searchParam"
           tal:attributes="id string:$idPrefix.row">
      <div metal:use-macro="macros/?param" />
</div>


<metal:text define-macro="type">
  <tr>
    <td metal:use-macro="macros/minus"/>
    <td colspan="3">
      <h2 i18n:translate="">Type(s) to search for</h2>
    </td>
  <tr>
    <td></td>
    <td>
      <label for="text"
             tal:attributes="for string:$idPrefix.text">
        <span i18n:translate="">Type</span>:</label>
      <select name="text"
              tal:attributes="name string:$namePrefix.text;
                            id string:$idPrefix.text;">
        <tal:types repeat="type item/typesForSearch">
          <option value="loops:*"
                  i18n:translate=""
                  tal:attributes="value type/token"
                  tal:content="type/title">Topic</option>
        </tal:types>
      </select>
      <input type="button" value="+"
             title="Add type"
             tal:condition="nothing" />&nbsp;
    </td>
    <td colspan="2"></td>
  </tr>
</metal:text>


<metal:text define-macro="text">
  <tr>
    <td metal:use-macro="macros/minus"/>
    <td colspan="3">
      <h2 i18n:translate="">Text-based search</h2>
    </td>
  <tr>
    <td></td>
    <td>
      <input type="checkbox" checked
             name="title" id="title" value="yes"
             tal:attributes="name string:$namePrefix.title;
                             id string:$idPrefix.title;" />
      <label for="title"
             i18n:translate=""
             tal:attributes="for string:$idPrefix.title">Title</label>
      <input type="checkbox"
             name="full" id="full" value="yes"
             tal:attributes="name string:$namePrefix.full;
                             id string:$idPrefix.full;" />
      <label for="full"
             i18n:translate=""
             tal:attributes="for string:$idPrefix.full">Full text</label>&nbsp;&nbsp;
    </td>
    <td>
      <label for="text"
             tal:attributes="for string:$idPrefix.text">
        <span i18n:translate="">Search text</span>:</label>
    </td>
    <td>
      <input type="text" name="text"
             tal:attributes="name string:$namePrefix.text;
                             id string:$idPrefix.text;" />
      <input type="button" value="+"
             title="Add search word"
             tal:condition="nothing" />&nbsp;
    </td>
  </tr>
</metal:text>


<metal:text define-macro="concept">
  <tr>
    <td metal:use-macro="macros/minus"/>
    <td colspan="3">
      <h2 i18n:translate="">Search via related concepts</h2>
    </td>
  <tr tal:repeat="type item/presetSearchTypes">
    <tal:preset define="rowNum item/rowNum;
                        idPrefix string:$basicIdPrefix.$rowNum;
                        namePrefix string:search.$rowNum;">
      <td></td>
      <td>
        <span i18n:translate="">Type</span>:
        <b tal:content="type/title" i18n:translate="" />
        <input type="hidden" name="type" value=""
               tal:attributes="name string:$namePrefix.type;
                               value type/token" />
      </td>
      <td>
        <label for="text"
               tal:attributes="for string:$idPrefix.text">
          <span i18n:translate="">Concept for Search</span>:</label>
      </td>
      <td>
        <select name="text_selected"
                tal:attributes="name string:$namePrefix.text_selected;
                                id string:$idPrefix.text;">
          <tal:concepts repeat="concept python: item.conceptsForType(type['token'])">
            <option tal:attributes="value concept/token"
                    i18n:translate=""
                    tal:content="concept/title">Zope Corp</option>
          </tal:concepts>
        </select>
      </td>
    </tal:preset>
  </tr>
  <tr>
    <td></td>
    <td>
      <label for="type"
             tal:attributes="for string:$idPrefix.type">
        <span i18n:translate="">Type</span>:</label>
      <select name="type"
              tal:attributes="name string:$namePrefix.type;
                              id string:$idPrefix.type;
                              onChange string:setConceptTypeForComboBox('$idPrefix.type', '$idPrefix.text')">
        <tal:types repeat="type item/conceptTypesForSearch">
          <option value="loops:*"
                  i18n:translate=""
                  tal:attributes="value type/token"
                  tal:content="type/title">Topic</option>
        </tal:types>
      </select>&nbsp;&nbsp;
    </td>
    <td>
      <label for="text"
             tal:attributes="for string:$idPrefix.text">
        <span i18n:translate="">Concept for Search</span>:</label>
      <input type="text" name="text"
             tal:condition="nothing"
             tal:attributes="name string:$namePrefix.text;
                             id string:$idPrefix.text;" />
      <input type="button" value="+"
             title="Add type"
             tal:condition="nothing" />&nbsp;
    </td>
    <td>
      <tal:combo tal:define="dummy item/initDojo">
        <div dojoType="dojox.data.QueryReadStore" jsId="conceptSearch"
             url="listConceptsForComboBox.js?searchType=" >
        </div>
        <input dojoType="dijit.form.FilteringSelect" store="conceptSearch"
               autoComplete="False" labelAttr="label"
               name="concept.search.text" id="concept.search.text"
               tal:attributes="name string:$namePrefix.text;
                               id string:$idPrefix.text" />
      </tal:combo>
    </td>
  </tr>
</metal:text>


<td metal:define-macro="minus">
      <input type="button" value="&minus;"
             title="Remove search parameter"
             tal:condition="python: param not in ['type', 'text', 'concept']" />&nbsp;
</td>
