<tal:block metal:use-macro="python:here.getFormsTool().getForm('site_admin_template').macros['page']">

<h1 metal:fill-slot="title" i18n:translate="">Edit list of links</h1>

<tal:block metal:fill-slot="section"
  tal:define="site_url here/getSitePath;
        id python:request.get('id', '');
        linkslist python:here.getPortletsTool().getLinksListById(id);
        item python:request.get('item', '')">
<tal:block tal:condition="python:linkslist is not None">
[<a tal:attributes="href string:${site_url}/admin_linkslists_html" i18n:translate="">Back to the list of links</a>]<br /><br />
<fieldset><legend i18n:translate="">Change the list title</legend>
<form method="post" tal:attributes="action string:${site_url}/admin_editlinkslist">
  <div class="field">
    <label for="title" i18n:translate="">Title</label>
    <input type="title" name="title" tal:attributes="value linkslist/title" size="50"/>
  </div>
  <p>
    <input type="hidden" name="id" tal:attributes="value linkslist/id" />
    <input type="submit" value="Update" i18n:attributes="value" />
  </p>
</form>
</fieldset>
<tal:block tal:define="record_data python:linkslist.get_link_item_data(item)">
<a name="editlink"></a>
<form method="post" tal:attributes="action python:test(record_data[0]=='add', '%s/admin_addlink' % site_url, '%s/admin_editlink' % site_url)">
<fieldset><legend tal:condition="python:item==''" i18n:translate="">Add new link</legend>
<legend tal:condition="python:item!=''" i18n:translate="">Edit link</legend>
  <div class="field">
    <label for="title" i18n:translate="">Title</label>
    <input type="text" name="title" size="50" tal:attributes="value python:record_data[2]" />
  </div>
  <div class="field">
    <label for="description" i18n:translate="">Description</label>
    <input type="text" name="description" size="50" tal:attributes="value python:record_data[3]" />
  </div>
  <div class="field">
    <label for="url" i18n:translate="">URL</label>
    <input type="text" name="url" size="50" tal:attributes="value python:record_data[4]" />
  </div>
  <div class="field">
    <label for="relative" i18n:translate="">check if it is a local link</label>
    <input type="checkbox" name="relative" tal:attributes="checked python:record_data[5]==1" />
    <em i18n:translate="">(relative path will be provided)</em>
  </div>
  <div class="field">
    <label for="url" i18n:translate="">Permission</label>
    <p i18n:translate="">
      Choose one of the permissions defined in the system if you want this link to be displayed only
      for users with (at least) that permission.</p>
    <select name="permission" tal:define="current python:record_data[6]">
      <option value="" i18n:translate="">[None]</option>
      <option tal:repeat="perm options/permission_list"
          tal:attributes="value perm/zope_permission;
                          selected python:perm['zope_permission'] == current"
          tal:content="perm/title" />
    </select>
  </div>
  <div class="field">
    <label for="order" i18n:translate="">Order</label>
    <input type="text" name="order" size="3" tal:attributes="value python:record_data[7]" />
  </div>
  <p>
    <input type="hidden" name="id" tal:attributes="value linkslist/id" />
    <input type="hidden" name="item" tal:attributes="value item" />
    <input type="submit" tal:attributes="value python:test(record_data[0]=='add', 'Add', 'Update')" i18n:attributes="value" />
  </p>
</fieldset>
</form>
</tal:block>

<br />
<h2 i18n:translate="">Available links</h2>
<p i18n:translate="">Click on a link title to edit its attributes.</p>
<form method="post" tal:attributes="action string:${site_url}/admin_deletelinks">
  <table class="datatable">
  <thead>
    <tr>
      <th class="scope-col" scope="col">&nbsp;</th>
      <th class="scope-col" scope="col" i18n:translate="">Title</th>
      <th class="scope-col" scope="col" i18n:translate="">Description</th>
      <th class="scope-col" scope="col" i18n:translate="">URL</th>
      <th class="scope-col" scope="col" i18n:translate="">Permission</th>
      <th class="scope-col" scope="col" i18n:translate="">Order</th>
    </tr>
  </thead>
  <tbody>
    <tr tal:repeat="record linkslist/get_links_list" tal:attributes="class python:test(path('repeat/record/odd'), 'zebraodd', 'zebraeven')">
      <td><input type="checkbox" name="ids" tal:attributes="value record/id" /></td>
      <td><a tal:attributes="href string:${site_url}/admin_linkslist_html?id=${linkslist/id}&item=${record/id}#editlink" tal:content="record/title">title</a></td>
      <td tal:content="record/description">description</td>
      <td tal:content="python:here.utTruncateString(test(record.relative, '%s%s' % (site_url, record.url), record.url), 40)">url</td>
      <td tal:content="python:options['permission_titles'].get(record.permission, '')">permission</td>
      <td tal:content="record/order">Order</td>
    </tr>
  </tbody>
  </table>
  <input type="hidden" name="id" tal:attributes="value linkslist/id" />
  <input type="submit" name="delete" value="Delete" i18n:attributes="value" />
</form>
</tal:block>
<tal:block tal:condition="python:linkslist is None" i18n:translate="">
  Invalid links list.
</tal:block>
</tal:block>

</tal:block>
