<script>ST.state.push()</script>
<tal:script
    tal:replace="structure scriptlocal:container_id view/manager/html_id" />
<tal:block i18n:domain="schooltool"
           define="batch nocall:view/manager/batch|nothing;
                   search_id view/search_id">
  <tal:if condition="batch">
    <div class="count" i18n:translate="">
      Showing
      <span i18n:name="count" tal:content="batch/length"/>
      of
      <span i18n:name="total" tal:content="batch/full_size"/>
      items
    </div>
  </tal:if>
  <fieldset>
    <legend><span tal:content="view/legend">Search</span></legend>
    <div class="row" tal:define="title_id view/search_title_id">
      <div class="label">
        <label tal:attributes="for title_id">
          <span tal:content="view/title">[title]</span>
        </label>
      </div>
      <div class="widget">
        <input type="text" class="text-widget"
               tal:attributes="id title_id;
                               name title_id;
                               value python:request.get(title_id)"
               />
      </div>
    </div>
    <div class="row" tal:define="course_id view/search_course_id">
      <div class="label">
        <label tal:attributes="for course_id">
          <span i18n:translate="">Filter by...</span>
        </label>
      </div>
      <div class="widget">
        <select tal:attributes="id course_id; name course_id"
                class="select-widget">
          <option i18n:translate="">All courses</option>
          <option tal:repeat="course view/courses"
                  tal:content="course/title"
                  tal:attributes="value course/id;
                                  selected python:course['id'] == request.get(course_id)"/>
        </select>
        <tal:script replace="structure scriptlocal: course_id; search_id;" />
        <script>
          $(ST.dialogs.jquery_id(ST.local.course_id)).change(
            function(){
              var course_id = ST.local.course_id;
              var container_id = ST.local.container_id;
              var search_id = ST.local.search_id;
              return function(element) {
                return ST.table.on_form_submit(
                    container_id, document.getElementById(search_id));
              }}());
        </script>
      </div>
    </div>
    <div class="row" tal:define="term_ids view/search_term_ids"
         tal:condition="view/multiple_terms">
      <div class="label">
        <span i18n:translate="">Terms</span>
      </div>
      <div class="widget">
        <div tal:repeat="term view/terms">
          <tal:block define="id string:${view/search_term_ids}-${term/id}">
            <input tal:attributes="value term/id;
                                   id id;
                                   name term_ids;
                                   checked term/checked"
                   type="checkbox" />
            <label tal:attributes="for id">
              <span class="label" tal:content="term/title" />
            </label>
            <tal:script
                replace="structure scriptlocal: term_id id; search_id" />
            <script>
            $(ST.dialogs.jquery_id(ST.local.term_id)).click(
                function(){
                    var search_id = ST.local.search_id;
                    var container_id = ST.local.container_id;
                    return function(button) {
                        return ST.table.on_form_submit(container_id, button);
                    }}());
            </script>
          </tal:block>
        </div>
      </div>
    </div>
  </fieldset>
  <div class="buttons">
    <input type="submit" name="SEARCH_BUTTON" value="Search"
           tal:attributes="id search_id"
           class="button-ok" i18n:attributes="value" />
    <tal:script replace="structure scriptlocal: search_id" />
    <script>
      $(ST.dialogs.jquery_id(ST.local.search_id)).click(
         function(){
             var search_id = ST.local.search_id;
             var container_id = ST.local.container_id;
             return function(button) {
                  return ST.table.on_form_submit(container_id, button);
             }}());
    </script>
  </div>
</tal:block>
<script>ST.state.pop()</script>
