<html metal:use-macro="context/main_template/macros/master" i18n:domain="cmfeditions">

  <tal:block metal:fill-slot="head_slot">
        <link rel="stylesheet" type="text/css" href="compare.css" />
  </tal:block>

  <div metal:fill-slot="main"
       tal:define="pr nocall:context/portal_repository;
                   version_id python:request.get('version_id', None);
                   history python:pr.getHistoryMetadata(context);
                   revisions python:history.getLength(countPurged=False);
                   histrange python:range(revisions-1, -1, -1)"
                   tal:condition="python: pr.isVersionable(context)">
    <h1 class="documentFirstHeading"
        i18n:translate="versions_of_title">Revisions of
          "<span i18n:name="title" tal:replace="context/title_or_id">title</span>"
    </h1>

    <div>
        <span i18n:translate="box_last_modified">
          Last modified
        </span>
        <span tal:replace="python:context.toLocalizedTime(context.ModificationDate(),long_format=1)"
              tal:on-error="string:-" >
          August 16, 2001 at 23:35:59
        </span>
    </div>

    <form action="."
        method="post"
        tal:condition="history"
        tal:define="here_url context/absolute_url"
        tal:attributes="action string:${here_url}/versions_history">

        <table id="sortable"
            class="listing"
            summary="Content history"
            cellpadding="0" cellspacing="0"
            tal:define="current python:context.checkUpToDate(history)">
            <thead>
                <tr>
                  <th><tal:title i18n:translate="listingheader_key"
                      >Revision</tal:title></th>
                  <th><tal:title i18n:translate="listingheader_performed_by"
                      >Performed by</tal:title></th>
                  <th><tal:title i18n:translate="listingheader_date_and_time"
                  >Date and Time</tal:title></th>
                  <th><tal:title i18n:translate="listingheader_comment"
                      >Comment</tal:title></th>
                  <th><tal:title i18n:translate="listingheader_actions"
                      >Actions</tal:title></th>
                </tr>
            </thead>

            <tbody tal:define="isModified current/isModified;
                               reverted_vid current/reverted_vid;
                               isReverted current/isReverted">
                <tr class="CurrentVersion odd"
                    tal:condition="isModified">
                  <td class="VersionId"
                      tal:define="id current/version_id;">
                    <span i18n:translate="">Working Copy</span>
                  </td>
                  <td class="VersionUser">
                    <span tal:replace="context/Creator">user</span>
                  </td>
                  <td class="VersionDate">
                    <span tal:replace="python:context.toLocalizedTime(context.ModificationDate(),long_format=1)">2004/10/21 03:15 PM</span>
                  </td>
                  <td class="VersionComment">
                    <span i18n:translate="label_modifications_from_revision">
                      modifications from revision
                      <span tal:replace="reverted_vid" i18n:name="version_id" />
                    </span>
                    <span tal:condition="isReverted"
                           i18n:translate="label_previously_reverted">
                      (previously reverted)
                    </span>
                  </td>
                  <td class="VersionActions">
                    <ul>
                        <li tal:condition="exists:context/portal_diff">
                            <a href=""
                               style="text-decoration: none"
                               tal:attributes="href string:${here_url}/version_diff?version_id1=current&amp;version_id2=${reverted_vid}">
                              <span tal:condition="isReverted"
                                    i18n:translate="label_compare_to_revision">
                                Compare to revision 
                                <span tal:replace="reverted_vid"
                                      i18n:name="version_id" />
                              </span>
                              <span tal:condition="not:isReverted"
                                    i18n:translate="label_compare_to_previous_revision">
                                Compare to previous revision
                              </span>
                            </a>
                        </li>
                    </ul>
                  </td>
                </tr>
                <tal:block repeat="vdatai histrange">
                <tr tal:define="id     vdatai;
                                vdatafull   python:history.retrieve(vdatai, countPurged=False);
                                vdata       vdatafull/metadata;
                                current_version python:not current['isModified'] and current['version_id']==vdatai;
                                even repeat/vdatai/even;"
                    tal:attributes="class python:(current_version and 'CurrentVersion' or '') + (even and ' even' or '')">
                  <td class="VersionId">
                    <span tal:condition="current_version" i18n:translate="">Working Copy</span>
                    <span tal:condition="not:current_version" tal:content="id">1</span>
                    <a href="#"
                       class="version-table-version"
                       tal:attributes="href string:${here_url}/versions_history_form?version_id=${id}"
                       tal:condition="python:version_id!=id and not current_version"
                       i18n:translate="label_preview_version_link">(preview)</a>
                    <a href="#"
                       class="version-table-version"
                       tal:attributes="href string:${here_url}/versions_history_form?version_id=${id}#version_preview"
                       tal:condition="python:version_id==id"
                       i18n:translate="label_preview_version_below">(jump down)</a>
                  </td>
                  <td class="VersionUser">
                    <span tal:content="vdata/sys_metadata/principal">francesco</span>
                  </td>
                  <td class="VersionDate">
                    <span tal:content="python:context.toLocalizedTime(vdata['sys_metadata']['timestamp'],long_format=1)">2004/10/21 03:15 PM</span>
                  </td>
                  <td class="VersionComment">
                    <span tal:content="vdata/sys_metadata/comment" i18n:translate="">Draft version ready for comments from the group.</span>
                  </td>
                  <td class="VersionActions">
                    <ul>
                        <tal:diffs condition="exists:context/portal_diff">
                        <li tal:condition="not:current_version">
                            <a href=""
                               style="text-decoration: none"
                               tal:attributes="href string:${here_url}/version_diff?version_id1=current&amp;version_id2=${id}"
                               i18n:translate="label_compare_current">
                            Compare to current revision
                            </a>
                        </li>
                        <li tal:condition="not:repeat/vdatai/end">
                            <a href=""
                               style="text-decoration: none"
                               tal:define="prev_ver python:str(int(id)-1)"
                               tal:attributes="href string:${here_url}/version_diff?version_id1=${id}&amp;version_id2=${prev_ver}"
                               i18n:translate="label_compare_previous">
                            Compare to previous revision
                            </a>
                        </li>
                        </tal:diffs>
                        <li tal:condition="not:current_version">
                            <a href=""
                               style="text-decoration: none"
                               tal:attributes="href string:${here_url}/revertversion?version_id=${id}"
                               i18n:translate="label_revert">
                        Revert to this revision
                            </a>
                        </li>
                    </ul>
                  </td>
                </tr>
                </tal:block>
            </tbody>
          </table>

    </form>

    <form action="#"
        method="post"
        tal:define="here_url context/absolute_url"
        tal:attributes="action string:${here_url}/saveasnewversion"
        tal:condition="not: python:pr.supportsPolicy(context, 'at_edit_autoversion')">

        <fieldset>

            <div class="field">
              <label for="description"
                    i18n:translate="label_newversion">New version</label>

              <div class="formHelp" i18n:translate="help_versioncomment">
                At any moment you can save the content you just edited as a new revision. Enter below a comment to identify the version and hit the "Save as new revision" button.
              </div>
              <textarea cols="60"
                        rows="3"
                        id="versioncomment"
                        name="versioncomment"
                        ></textarea>
            </div>

            <input class="context"
                        type="submit"
                        name="saveversion"
                        value="Save as new revision"
                        i18n:attributes="value button_save_as_new_version"
                        />

        </fieldset>

    </form>

    <a name="version_preview">
      <label for="description" 
             tal:condition="version_id"
             i18n:translate="label_preview_version">
        Preview of Revision <span i18n:name="version_id" tal:replace="version_id">0</span>
      </label>
    </a>
    <div style="border:solid 1px gray"
         tal:condition="version_id">
      <tal:block define="vdata python:pr.retrieve(context, version_id);
                         version_view_macro python: context.get_macros(vdata);
                         context nocall:vdata/object;
                         portal_type python:context.getPortalTypeName().lower().replace(' ', '_');
                         object_title context/Title;
                         suppress_preview python:True;
                         view_macro python:version_view_macro;">
        <tal:preview condition="view_macro">
          <metal:use_body use-macro="view_macro" />
        </tal:preview>
        <tal:nopreview condition="not:view_macro">
          <div i18n:translate="">Preview is not available.</div>
        </tal:nopreview>
      </tal:block>
      
    </div>

  </div>
</html>
