<metal:block use-macro="container/macro_edit_view/macros/edit_view"
  xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  i18n:domain="silva_document">
  <metal:block fill-slot="edit_input"
    tal:define="
      source here/get_source | nothing;
      source_id source/id | nothing;
      "
    >
    <div>
      <tal:block i18n:translate="">source id</tal:block>&nbsp;<select name="id">
      <option disabled="disabled" i18n:translate="">Select an External Source...</option>
      <option 
        tal:repeat="av_source here/available_sources"
        tal:attributes="
          value python: av_source[0];
          title python: av_source[1].get_title();
          selected python: (source_id == av_source[0]) and 'selected' or nothing;
          ">
        <tal:block 
          define="sid python: av_source[0];stitle python: av_source[1].get_title();">
          <tal:block tal:condition="stitle" tal:replace="stitle" />
          (<span tal:replace="sid" />)
        </tal:block>
        </option>
      </select>
      &nbsp;
      <input class="button" type="submit" value="update" title="access key: alt-u" accesskey="u"
        tal:attributes="name string:${rel_url_start}/save:method" i18n:attributes="value;title" />
    </div>
    <tal:block condition="source">
      <div
        tal:define="
          form source/form | nothing;
          fields form/get_fields | nothing;
          has_parameters python: form and fields;
          current_parameters here/get_parameters;
          "
        >
        <strong tal:condition="not: has_parameters" i18n:translate="">
          No parameters to be filled for this source.
        </strong>
        <table class="csvtable" cellspacing="0" cellpadding="2" border="0" width="100%"
          tal:condition="has_parameters"
          >
          <thead>
            <tr>
              <th colspan="3">
                <strong i18n:translate="">Source parameters</strong>
              </th>
            </tr>
          </thead>
          <tbody>
            <tal:block repeat="field fields">
              <tr 
                tal:define="
                  iterate repeat/field/odd;
                  id field/id;
                  title python: field.get_value('title') or nothing;
                  description python: field.get_value('description') or nothing;
                  is_required field/is_required | nothing;
                  current_value current_parameters/?id | nothing;
                  "
                tal:attributes="class python: iterate and 'odd' or 'even'"
                >
                <td class="align-right">
                  <span tal:replace="title">
                    title
                  </span><span class="warning" tal:condition="is_required">*</span>
                </td>
                <td tal:content="structure python: field.render(value=current_value)" />
                <td tal:content="description" />
              </tr>
            </tal:block>
          </tbody>
        </table>
      </div></tal:block>
  </metal:block>

  <metal:block fill-slot="edit_notes"
  tal:define="source here/get_source | nothing;
    source_desc source/description | nothing">
    <ul class="tips">
      <li i18n:translate="">
      Select a source from the pulldown list.
      </li>
      <li>
      <span class="warning" i18n:translate="">Hit "update" to refresh the reference.</span>
      </li>
      <li i18n:translate="">
        Fill in the parameters (if necessary).
      </li>
    </ul>

    <strong tal:condition="source_desc" i18n:translate="">Source description:</strong>
    <span tal:content="source_desc" />
  </metal:block>
</metal:block>
