<metal:block use-macro="python:here.standard_template_macro('light')">

<metal:block metal:fill-slot="header-title">
	<title><tal:block i18n:translate="">Search</tal:block> | <span tal:replace="here/site_title" /></title>
</metal:block>

<metal:block metal:fill-slot="head" tal:define="
        curr_lang python:request.get('lang', None) or here.gl_get_selected_language();">
    <script type="text/javascript" tal:attributes="src string:${here/getSitePath}/core_js"></script>
    <script type="text/javascript" tal:attributes="src string:${here/getSitePath}/calendar_js"></script>
    <script type="text/javascript" tal:attributes="src string:${here/getSitePath}/datetime_js"></script>
    <script type="text/javascript" src="/++resource++Products.Naaya/lib/datatables/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="/++resource++Products.Naaya/lib/datatables/moment.min.js"></script>
    <script type="text/javascript" src="/++resource++Products.Naaya/lib/datatables/datetime-moment.js"></script>
    <link rel="stylesheet" type="text/css" href="/++resource++Products.Naaya/lib/datatables/jquery.dataTables.css" />
    <script type="text/javascript">
        $(document).ready(function(){
            $.fn.dataTable.moment('DD MMM YYYY');
            $('.sortable').each(function(){
              $(this).dataTable({
                "bStateSave": true,
                'aaSorting': [[3, "desc"]],
                'sPaginationType': 'full_numbers',
                'aLengthMenu': [[10, 25, 50, -1],
                                [10, 25, 50, "All"]],
                'iDisplayLength': 10,
                'oLanguage': {
                  'sSearch': 'Live filter results:'
                }
              });
            });
        });

    </script>
    <style>
      .old_item {
          white-space: nowrap;
      }
      .old_item:after {
          content: "";
          display: inline-block;
          *display: inline;
          *zoom: 1;
          width: 16px;
          height: 16px;
          vertical-align: middle;
          margin-top: -2px;
          margin-left: 3px;
          background: url('misc_/Naaya/info.png') no-repeat;
      }
    </style>
</metal:block>

<metal:block metal:fill-slot="body">
  <h1 i18n:translate="">Free text search in this portal</h1>
  <tal:b1 tal:define="
      query python:request.get('query', '');
      langs here/gl_get_languages;
      languages python:here.utConvertToList(request.get('languages', [here.gl_get_selected_language()]));
      releasedate python:request.get('releasedate', None);
      releasedate_range python:request.get('releasedate_range', 'min');
      meta_types_list python:[meta for meta in here.searchable_content if meta.replace(' ','_') in request.form.keys()];
      meta_types python:test(len(meta_types_list), meta_types_list, here.searchable_content);">
    <div class="searchQuery">
      <tal:b2 define="
        results python:here.internalSearch(query, languages, releasedate, releasedate_range, meta_types);
        object_list results/object_list;
        error results/error;
        age here/getItemsAge;">
        <div class="searchQueryFilters">
          <h2><strong>Search filters</strong></h2>
          <form method="get" name="frmSearch" action="search_html">
            <label for="query" i18n:translate="">Enter your search term(s):</label>
            <input type="text" name="query:utf8:ustring" id="query"
              tal:attributes="value python:request.get('query', '')"
              size="40" maxLength="100" />
            <p class="form-errors" tal:condition="error" tal:content="error" />
            <div tal:condition="python:len(langs)>1" style="margin-top:1em;">
              <label i18n:translate="">Search items in:</label>
              <tal:b3 repeat="item here/gl_get_languages_mapping">
                <input name="languages" type="checkbox" style="margin:0 3px;"
                  tal:attributes="
                    value item/code;
                    checked python:item['code'] in languages;
                    id string:language_${item/code}" />
                <label tal:attributes="for string:language_${item/code}"
                  tal:content="item/name" />
              </tal:b3>
            </div>
            <div style="margin-top:1em;">
              <label for="releasedate" i18n:translate="">Published:</label>
              <select name="releasedate_range" id="releasedate_range"
                  style="vertical-align:middle;">
                <option value="max" i18n:translate=""
                  tal:attributes="selected python:releasedate_range=='max'">before</option>
                <option value="min" i18n:translate=""
                  tal:attributes="selected python:releasedate_range=='min'">after</option>
              </select>
              <input type="text" name="releasedate" class="vDateField"
                id="releasedate" size="10" tal:attributes="value releasedate" />
              <noscript><em i18n:translate="">(dd/mm/yyyy)</em></noscript>
            </div>
            <div style="margin-top:1em;">
              <label for="meta_types" i18n:translate="">Content type(s):</label>
              <br />
              <input type="checkbox" checked="checked" class="toggle-all"
                id="toggle-all" rel="content-types" />
              <label for="toggle-all" i18n:translate="">All types</label>
              <br />
              <ul style="list-style-type:none;" id="meta_types">
                <tal:b3 repeat="item here/searchable_content">
                  <li tal:define="item_label python:here.get_meta_type_label(item)">
                  <input type="checkbox" style="margin:0 3px;" class="content-types"
                         tal:attributes="checked python:item in meta_types;
                                         id python:item.replace(' ', '_');
                                         name python:item.replace(' ', '_');" />
                  <label tal:attributes="for python:item.replace(' ', '_')"
                    tal:content="item_label"></label></li>
                </tal:b3>
              </ul>
            </div>
            <br clear="all" />
            <input type="submit" value="Search" class="styled_button"
              i18n:attributes="value" />
            <input type="hidden" name="sort_order" value="" />
            <input type="hidden" name="sort_by" value="" />
          </form>
        </div>
        <tal:b3 condition="not:error">
          <tal:b4 condition="object_list">
            <tal:b5 define="records object_list;">
              <h2 style="padding-left: 0.5em; margin-bottom: 1em;">
                <strong i18n:translate="">Search Results:</strong></h2>
              <table class="sortable" border="0" width="100%">
                <thead>
                  <tr>
                    <th i18n:translate="">Type</th>
                    <th i18n:translate="">Title/Abstract</th>
                    <th i18n:translate="">Last updated</th>
                    <th i18n:translate="">Upload date (for files)</th>
                  </tr>
                </thead>
                <tbody>
                  <tr tal:repeat="record records">
                    <tal:b6 condition="record/can_be_seen">
                      <td>
                        <img tal:define="icon python:here.rstk['get_object_view_info'](record)['icon']"
                             tal:attributes="src icon/url; title icon/title; alt icon/title"
                             style="text-align: middle" />
                      </td>
                      <td>
                        <a tal:attributes="href record/absolute_url"
                          tal:content="record/title_or_id"></a>
                        <span tal:condition="record/description">
                          <br />
                          <span tal:replace="python:here.utTruncateString(here.utStripAllHtmlTags(record.description), 200)" /></span>
                      </td>
                      <td tal:condition="python:len(langs)>1">
                        <tal:b7 tal:repeat="lang langs">
                          <span tal:condition="python:record.istranslated(lang)"
                            tal:content="python:here.gl_get_language_name(lang)" />
                        </tal:b7>
                      </td>
                      <td tal:attributes="
                        class python:test(
                          here.internal_get_item_age(record.bobobase_modification_time(), age)==1,
                          'old_item',
                          None)"
                          style="text-align:right"
                          title="Older than 12 months" i18n:attributes="title"
                          tal:content="python:record.bobobase_modification_time().strftime('%d %b %Y')" />
                      <td style="text-align: center" style="text-align:right"
                          tal:content="record/upload_date|string:-" />
                    </tal:b6>
                  </tr>
                </tbody>
              </table>
            </tal:b5>
          </tal:b4>
          <tal:b4 tal:condition="not:object_list">
            <strong i18n:translate="">No results were found for this query.</strong>
          </tal:b4>
        </tal:b3>
      </tal:b2>
    </div>
    <div class="tooltip">
      <strong i18n:translate="">Search tips</strong>
      <table>
        <tr>
            <td valign="top" class="tip_item" i18n:translate="">
              fish <strong i18n:name="AND">AND</strong> biodiversity</td>
            <td valign="top" i18n:translate="">
              the two words occur in the document in any order but not necessarily together</td>
        </tr>
        <tr>
            <td valign="top" class="tip_item" i18n:translate="">
              fish <strong i18n:name="OR">OR</strong> biodiversity</td>
            <td valign="top" i18n:translate="">
              either of the words occur in the document</td>
        </tr>
        <tr>
            <td valign="top" class="tip_item" i18n:translate="">
              fish and <strong i18n:name="NOT">NOT</strong> biodiversity</td>
            <td valign="top" i18n:translate="">
              the word fish and not the word biodiversity occur</td>
        </tr>
        <tr>
            <td valign="top" class="tip_item">
              <tal:block i18n:translate="">bio</tal:block><strong>*</strong></td>
            <td valign="top" i18n:translate="">
              everything starting with <em i18n:name="bio" i18n:translate="">bio</em></td>
        </tr>
      </table>
      <span i18n:translate="">This search is performed on the current website.</span>
    </div>
    <br clear="all" />
  </tal:b1>
</metal:block>
</metal:block>
