<metal:body define-macro="body"
            tal:define="has_image here/size">
<metal:at use-macro="here/edit_macros/macros/body">

  <metal:block fill-slot="widgets">
    <tal:tabbed tal:condition="allow_tabbing | nothing">
      <fieldset tal:define="sole_fieldset python:len(fieldsets) == 1"
                tal:repeat="fieldset fieldsets"
                tal:attributes="id string:fieldset-${fieldset}"
                tal:omit-tag="sole_fieldset">
        <legend id=""
                tal:content="python: view.getTranslatedSchemaLabel(fieldset)"
                tal:attributes="id string:fieldsetlegend-${fieldset}"
                tal:condition="not:sole_fieldset" />
        <tal:fields repeat="field python:schematas[fieldset].editableFields(here, visible_only=True)">
          <metal:fieldMacro use-macro="python:here.widget(field.getName(), mode='edit')" />
        </tal:fields>
      </fieldset>
      <fieldset id="fieldset-crops"
                tal:condition="has_image">
        <legend id="fieldsetlegend-crops">Crops</legend>
        <metal:crops use-macro="here/richimage_edit/macros/crops_edit" />
      </fieldset>
    </tal:tabbed>
    <tal:nottabbed tal:condition="not: allow_tabbing | nothing">
        <tal:fields repeat="field python:schematas[fieldset].editableFields(here, visible_only=True)">
          <metal:fieldMacro use-macro="python:here.widget(field.getName(), mode='edit')" />
        </tal:fields>
        <tal:has_image condition="has_image">
          <metal:crops use-macro="here/richimage_edit/macros/crops_edit" />
        </tal:has_image>
    </tal:nottabbed>
  </metal:block>

</metal:at>
</metal:body>


<metal:crops define-macro="crops_edit"
             tal:define="field python: here.getField('image');">

    <tal:crops repeat="crop_id python:field.crops.keys()">
    <div class="field"
         tal:define="x python:field.crops[crop_id][2];
                     y python:field.crops[crop_id][3];
                     crop_edit_url string:${here/absolute_url}/edit_crop?crop=${crop_id}&width=${x}&height=${y};
                     crop_tag python:field.crop_tag(here, crop_id=crop_id)">

      <label for="" xtal:attributes="for " xi18n:translate=""
            tal:define="crop_name python:crop_id.replace('_', ' ').capitalize()"
            tal:content="crop_name">Crop name</label>

      <a title="edit"
         tal:attributes="href crop_edit_url;
                         id string:${crop_id}_crop_edit"
         i18n:attributes="title">
        <img tal:replace="structure context/edit.gif" />
      </a>

      <div class="formHelp"
           tal:content="python:field.crops[crop_id]"></div>

      <div class="field"
           tal:condition="crop_tag">
        <a title="edit"
            tal:attributes="href crop_edit_url"
            i18n:attributes="title">
          <img tal:replace="structure crop_tag"/>
        </a>
      </div>

    </div>
    </tal:crops>

</metal:crops>