<metal:define-macro define-macro="sources">
<form action="." name="sources" method="post"
  tal:define="model request/model;
              results model/find_sources;
              startat python:request.get('start',nothing) or options.get('startat',nothing) or 0;
              batch python:modules['ZTUtils'].Batch(results, size=10, start=int(startat));
              previous python:batch.previous;
              next python:batch.next;
              sources python:context.prepare_sources(batch);
              user_role context/get_user_role;">
 <table class="listing">
  <thead>
   <tal:block replace="nothing">
     ______________ top-controls row ______________
   </tal:block>
   <tr class="top-controls">
    <td colspan="3">
     <h3 i18n:translate="">
        sources
     </h3>
    </td>
   </tr>
  </thead>

  <span tal:replace="nothing"> ______________ table header ______________ </span>
  <tbody class="unblock">
   <tr tal:condition="python:len(sources) != 0">
    <th i18n:translate="" width="3%" nowrap="1">in use</th>
    <th i18n:translate="" width="40%">path</th>
    <th i18n:translate="">title</th>
   </tr>

   <span tal:replace="nothing"> ___________ listing iteration ___________ </span>
    <tal:repeat repeat="source sources">
     <tal:define define="
        obj source/object;
        id source/index;
        object obj/getObject;
        object_path obj/getPath;
        object_url object/absolute_url;
        ">
      <tr tal:attributes="class python:repeat['source'].odd() and 'odd' or 'even'">

       <span tal:replace="nothing"> _______ checkbox + icon _______ </span>
       <td class="listing-left">
         <input type="checkbox" name="cb:list" value="value"
           tal:attributes="value string:cb_${id}; checked source/check_checkbox" />
         <a href="edit" title="Edit this source" i18n:attributes="title"
           tal:attributes="href string:${object_url}/edit/tab_edit"><img tal:replace="structure python:view.render_icon(object)" /></a>
       </td>

       <span tal:replace="nothing"> _______ id cell _______ </span>
       <td>
         <a title="Edit this item" i18n:attributes="title"
           tal:attributes="href string:${object_url}/edit"
           tal:content="object_path">id</a>
       </td>

       <span tal:replace="nothing"> _______ title cell _______ </span>
       <td>
         <tal:block condition="python:object.get_title_or_id() != ''">
           <span tal:replace="structure string:${object/get_title_or_id}">title</span>
         </tal:block>
         <span class="warning" tal:condition="not: source/check_checkbox">
           &nbsp;<tal:i18n i18n:translate="">(not activated)</tal:i18n>
         </span>
         <tal:block condition="python:obj.get_title == ''">
           &nbsp;
         </tal:block>
       </td>

      </tr>
     </tal:define>
    </tal:repeat>

    <span tal:replace="nothing"> ______________ if no records ______________ </span>
    <tal:check condition="python:len(sources) == 0 and not model.get_default()">
      <tr class="focus-light">
        <td colspan="3">
          <i i18n:translate="">There are no newssources available.</i>
        </td>
      </tr>
      <tr class="divider">
       <td colspan="3">
         <img tal:attributes="src string:${silva_root}/globals/pixel.gif" width="1" height="1" />
       </td>
      </tr>
    </tal:check>
    <!-- /iteration -->

  </tbody>

  <tfoot>
    <tal:check condition="python:len(sources) != 0">

      <span tal:replace="nothing"> ______________ controls for chief ______________ </span>
      <tr class="controls">
        <td colspan="3">
          <tal:if condition="python:user_role == 'Editor'">
            <input type="hidden" name="start" tal:attributes="value startat">
            <input class="button" 
              style="float:right"
              type="submit"
              name="use_sources:method"
              value="update sources"
              title="Use selected sources in this filter: alt-u"
              accesskey="u"
              i18n:attributes="title;value"
            />
            <input style="display: none"
              id="select_all_button"
              class="button" 
              type="submit" 
              name="selectButton" 
              value="select all" 
              sel_value="select all"
              desel_value="deselect all"
              title="select all items: alt-a" 
              accesskey="a" 
              onClick="toggleSelect(this); return false"
              i18n:attributes="value;sel_value;desel_value;title">
            <script type="text/javascript">
            // <![CDATA[

              if (document.forms[0]) {
                document.getElementById('select_all_button').style.display = 'inline';
              }

              isSelected = false;

              function toggleSelect(button) {
                var form = button.form;
                var check = true;
                if (isSelected) {
                  check = false;
                  isSelected = false;
                } else {
                  isSelected = true;
                };
                var inputs = form.getElementsByTagName('input');
                for (var i=0; i < inputs.length; i++) {
                  var child = inputs[i];
                  var type = child.getAttribute('type');
                  if (type != 'radio' && type != 'checkbox') {
                    continue;
                  };
                  if (check) {
                    child.setAttribute('checked', true);
                  } else {
                    // make very sure the checkbox is unchecked, the 
                    // setAttribute works on IE but not on Moz, the 
                    // removeAttribute the other way round, this doesn't
                    // seem to clash and who knows IE 8 will require both ;)
                    child.setAttribute('checked', null);
                    child.removeAttribute('checked');
                  };
                };
                var newvalue = isSelected ? button.getAttribute('desel_value') :
                                button.getAttribute('sel_value');
                button.setAttribute('value', newvalue);
              };
              
            // ]]>
            </script>
          </tal:if>
        </td>
      </tr>

    </tal:check>
  </tfoot>

  </table>
 <table width="50%">
   <tr>
     <td width="50%" align="left">
       &nbsp;
       <a href="#" tal:attributes="href string:${model/absolute_url}/edit/tab_edit?start:int=${previous/first}" tal:condition="previous" i18n:translate="">Previous</a>
     </td>
     <td width="50%" align="right">
       &nbsp;
       <a href="#" tal:attributes="href string:${model/absolute_url}/edit/tab_edit?start:int=${next/first}" tal:condition="next" i18n:translate="">Next</a></td>
   </tr>
 </table>
</form>
</metal:define-macro>