<tal:block tal:define="model request/ghost_model | request/model;
                       public options/public | nothing;
                       title_method python: test(public, 'get_title', 'get_title_editable');
                       append_to_url options/append_to_url | string:edit/tab_edit;
                       root_url model/get_root_url"
           xmlns:i18n="http://xml.zope.org/namespaces/i18n"
           i18n:domain="silvafind">
  <h2 class="heading"
      tal:content="model/get_title">
    title
  </h2>

  <div class="searchform" tal:condition="model/isFormNeeded">
    <form name="search_form" tal:attributes="action model/absolute_url">
      <table class="silvatable plain silvafind">
        <tbody>
          <tr tal:repeat="fieldView model/getPublicFieldViews">
            <td class="searchform-title"
                tal:content="fieldView/getTitle"
                i18n:translate="">
              a search object
            </td>
            <tal:block tal:define="widget_data fieldView/renderPublicWidget"
                       tal:condition="python: 'field_type' not in widget_data or nothing">
              <td class="store" tal:content="structure widget_data"></td>
            </tal:block>
            <tal:block tal:define="widget_data fieldView/renderPublicWidget"
                       tal:condition="widget_data/field_type|nothing">
              <td tal:condition="python:widget_data['field_type'] == 'MetatypeCriterionView'">
                <tal:block tal:define="name widget_data/name;
                                       name python:name +':list'">
                  <div class="silvafind-widget">
		            <select class="store" multiple="multiple" size="5"
			                tal:attributes="name name;
					                        id widget_data/name">
		              <option tal:condition="python: widget_data['value'] and widget_data['value'] != ['']"
			                  tal:content="widget_data/select_all_text"
			                  value="" />
		              <option tal:condition="python: not widget_data['value'] or
					                         widget_data['value'] == ['']"
			                  tal:content="widget_data/select_all_text"
			                  selected="selected"
			                  value=""/>
		              <tal:block tal:repeat="meta_type widget_data/meta_types">
		                <option tal:condition="python:meta_type in widget_data['value']"
			                    tal:content="python:meta_type.replace('Silva', '')"
			                    tal:attributes="value meta_type"
			                    selected="selected"/>
		                <option tal:condition="python:meta_type not in widget_data['value']"
			                    tal:content="python:meta_type.replace('Silva', '')"
			                    tal:attributes="value meta_type" />
		              </tal:block>
		            </select>
		          </div>
	            </tal:block>
	          </td>
              <td tal:condition="python:widget_data['field_type'] == 'FullTextCriterionView'">
                <div class="silvafind-widget">
		          <input class="store" type="text" size="20"
		                 tal:attributes="name widget_data/name;
				                         id widget_data/name;
				                         value widget_data/value" />
	            </div>
              </td>
              <td tal:condition="python:widget_data['field_type'] == 'IntegerRangeMetadataCriterionView'">
                <tal:block tal:define="input_name widget_data/name;
                                       name_lower python: input_name + '_lower';
                                       name_upper python: input_name + '_upper'">
                  <div class="silvafind-widget">
                    <span tal:content="widget_data/between"></span>
		            <input type="text"
			               tal:attributes="name name_lower;
					                       value widget_data/lower" />
		            <span tal:content="widget_data/and"></span>
		            <input type="text"
			               tal:attributes="name name_upper;
					                       value widget_data/upper" />
		            <small>* <span tal:content="widget_data/intg"></span></small>
		          </div>
	            </tal:block>
              </td>
              <td tal:condition="python:widget_data['field_type'] == 'DateRangeMetadataCriterionView'">
                <tal:block tal:define="input_name widget_data/name;
                                       name_begin python: input_name + '_begin';
                                       name_end python: input_name + '_end'">
                  <div class="silvafind-widget">
                    <span tal:content="widget_data/from"></span>
		            <input type="text"
			               tal:attributes="name name_begin;
					                       id widget_data/idname;
					                       value widget_data/begin"/>
		            <span tal:content="widget_data/to"></span>
		            <input type="text"
			               tal:attributes="name name_end;
					                       value widget_data/end"/>
		            <small>* yyyy/mm/dd</small>
                  </div>
                </tal:block>
              </td>
            </tal:block>
            <td class="searchform-description"
                tal:content="structure fieldView/getDescription">
              field description
            </td>
          </tr>
          <tr>
            <td></td>
            <td>
              <input name="search_submit"
                     class="button searchform-submit"
                     type="submit"
                     value="Search"
                     accesskey="s"
                     title="access key: alt-s"
                     i18n:attributes="value"
                     />
            </td>
            <td></td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>

  <tal:block tal:condition="request/form/keys">

    <div class="searchresults"
         tal:define="
                     resultparts python:model.searchResultsWithDescription(request);
                     results python:resultparts[0];
                     msg python:resultparts[1];
                     columnTitles model/getResultsColumnTitles;
                     batch python:model.getBatch(results);
                     fields python:model.getPublicResultFieldViews();
                     ">

      <h3 class="heading" i18n:translate=""
          tal:condition="python:len(batch)">Search Results</h3>

      <metal:block define-macro="searchinfo"
                   tal:condition="python:batch.size < len(results)">
        <table class="searchresult-header" width="100%">
          <tr>
            <td align="left" width="20%">
              <span class="searchresult-previous">
                <tal:block condition="request/previous_batch_url | nothing">
                  <a href="previousbatch" accesskey="p"
                     title="See the previous result listing: alt-p"
                     tal:attributes="href request/previous_batch_url"
                     i18n:attributes="title">
                    <img alt="Previous"
                         tal:define="image here/globals/left.gif"
                         tal:attributes="
                                         src image/absolute_url;
                                         width image/width;
                                         height image/height;
                                         "/>
                    <tal:block i18n:translate="">Previous</tal:block></a>
                </tal:block>
              </span>
            </td>
            <td align="center">
              <span class="searchresult-info" i18n:translate="">
                Showing results
                <tal:block replace="batch/start" i18n:name="batch_start" />
                to
                <tal:block replace="batch/end" i18n:name="batch_end" />
              </span>
              <span tal:condition="python:'totalresultcount' in [f.getName() for f in fields]" i18n:translate="">
                of about
                <tal:block replace="batch/total" i18n:name="total" />
              </span>
            </td>
            <td align="right" width="20%">
              <span class="searchresult-next">
                <tal:block condition="request/next_batch_url | nothing">
                  <a href="nextbatch" accesskey="n"
                     title="See the next result listing: alt-n"
                     tal:attributes="href request/next_batch_url"
                     i18n:attributes="title">
                    <tal:block i18n:translate="">Next</tal:block>
                    <img alt="Next"
                         tal:define="image here/globals/right.gif"
                         tal:attributes="
                                         src image/absolute_url;
                                         width image/width;
                                         height image/height;
                                         "/>
                  </a>
                </tal:block>
              </span>
          </td></tr>
        </table>
      </metal:block>

      <ul tal:condition="batch">
        <li tal:repeat="item batch">
          <tal:block define="ix repeat/item/index;"
                     condition="fields">
            <div class="searchresult">
              <tal:block repeat="field fields">
                <span class="searchresult-counter"
                      tal:define="num python:str(batch.start + ix)"
                      tal:condition="python:field.getName() == 'resultcount'"
                      tal:attributes="style python:'padding-left:%sex' % (3-len(num))"
                      tal:content="string:${num}.">
                  count
                </span>
                <tal:block define="result python:field.render(context, item)"
                           condition="python:not field.getName() in ['resultcount', 'totalresultcount']">
                  <span tal:condition="python:same_type(result, [])"
                        tal:repeat="item result"
                        tal:replace="structure item" />
                  <span tal:condition="python:not same_type(result, [])"
                        tal:replace="structure result" />
                </tal:block>
              </tal:block>
            </div>
          </tal:block>
        </li>
      </ul>

      <div metal:use-macro="here/render_helper/macros/searchinfo"/>
      <p class="searchresult-nomatch searchresult-header"
         tal:condition="python:not len(batch) and msg != 'empty'">
        <tal:block condition="msg" content="msg"/>
        <tal:block condition="not:msg" i18n:translate="">
          No items matched your search.
        </tal:block>
      </p>
    </div>

  </tal:block>
</tal:block>
