<tal:comment replace="nothing">View macro for a File.</tal:comment>
<metal:view define-macro="view"
            tal:define="info python: contextObj.getFileInfo(value);
                        empty not: info/size;
                        imageSrc string:${contextObj/absolute_url}/download?name=$name">
  <tal:file condition="python: not empty and not widget['isImage']">
    <a tal:attributes="href imageSrc"
       tal:content="info/filename">
    </a>&nbsp;&nbsp;-
    <i class="discreet" tal:content="python:'%sKb' % (info['size'] / 1024)"></i>
  </tal:file>
  <tal:image condition="python: not empty and widget['isImage']">
    <img tal:attributes="src python: imageSrc" />
  </tal:image>
  <tal:nothing tal:condition="empty">-</tal:nothing>
</metal:view>

<tal:comment replace="nothing">Edit macro for an File.</tal:comment>
<metal:edit define-macro="edit"
            tal:define="info python: contextObj.getFileInfo(value);
                        empty not: info/size;">

 <tal:showFile condition="not: empty">
  <metal:call use-macro="app/ui/widgets/file/macros/view"/><br/>
 </tal:showFile>
 <tal:editButtons condition="not: empty">
  <tal:comment replace="nothing">Keep the file unchanged.</tal:comment>
  <input type="radio" value="nochange"
         tal:attributes="checked python:test(info['size']!=0, 'checked', None);
                         name string:${name}_delete;
                         id string:${name}_nochange;
                         onclick string:document.getElementById('${name}_file').disabled=true;"/>
  <label tal:attributes="for string:${name}_nochange">Keep the file unchanged</label>
  <br/>
  <tal:comment replace="nothing">Delete the file.</tal:comment>
  <tal:delete condition="not: widget/required">
  <input type="radio" value="delete"
         tal:attributes="name string:${name}_delete;
                         id string:${name}_delete;
                         onclick string:document.getElementById('${name}_file').disabled=true;"/>
  <label tal:attributes="for string:${name}_delete">Delete the file</label>
  <br/>
  </tal:delete>
  <tal:comment replace="nothing">Replace with a new file.</tal:comment>
  <input type="radio" value=""
         tal:attributes="checked python:test(info['size']==0, 'checked', None);
                         name string:${name}_delete;
                         id string:${name}_upload;
                         onclick string:document.getElementById('${name}_file').disabled=false"/>
  <label tal:attributes="for string:${name}_upload;">Replace it with a new file</label>
  <br/>
 </tal:editButtons>
 <tal:comment replace="nothing">The upload field.</tal:comment>
 <input type="file"
       tal:attributes="name string:${name}_file;
                       id string:${name}_file;
                       size widget/width"/>
 <script type="text/javascript" 
         tal:define="isDisabled python:test(empty, 'false', 'true')"
         tal:content="string: document.getElementById('${name}_file').disabled=$isDisabled;">
 </script>
</metal:edit>

<tal:comment replace="nothing">Cell macro for an File.</tal:comment>
<metal:cell define-macro="cell">
  <metal:call use-macro="app/ui/widgets/file/macros/view"/>
</metal:cell>

<tal:comment replace="nothing">Search macro for an File.</tal:comment>
<metal:search define-macro="search"></metal:search>
