<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="zopyx.plone.smashdocs">
<body>


<metal:override fill-slot="top_slot"
    tal:define="disable_column_one python:request.set('disable_plone.leftcolumn',1);
                disable_column_two python:request.set('disable_plone.rightcolumn',1);"/>

<metal:main fill-slot="content-core" tal:define="is_configured view/is_configured">

    <link rel="stylesheet" type="text/css" tal:attributes="href string:${portal_url}/++resource++zopyx.plone.smashdocs/styles.css"/>

    <tal:loop repeat="message view/smashdoc_actions/messages">
        <div class="label message" tal:content="message" />
    </tal:loop>

    <div id="sd-actions" tal:condition="is_configured">
        <tal:loop repeat="action view/smashdoc_actions/actions">

            <form class="sd-action" id="action-new" 
                tal:condition="python: action['id'] == 'create'"
                  method="post" 
                  tal:attributes="action action/url">
                <legend i18n:translate="">New</legend>
                <div class="sd-help" i18n:translate="help_new_document">Create a new empty document in Smashdocs</div>
                <input type="submit" class="" id="submit-new" tal:attributes="value action/title"/>
            </form>
            
            <form class="sd-action" id="action-upload"
                tal:condition="python: action['id'] == 'upload'"
                  method="post" enctype="multipart/form-data" 
                  tal:attributes="action action/url">
                <legend i18n:translate="">Upload</legend>
                <div class="sd-help" i18n:translate="help_upload_document">Create a new Smashdocs document and upload a DOCX as content</div>
                <input type="file" name="file"/>
                <input type="submit" class="" id="submit-upload" tal:attributes="value action/title"/>
            </form>

            <form class="sd-action" tal:condition="python: action['id'] in ('read')">
                <legend i18n:translate="">Read</legend>
                <div class="sd-help" i18n:translate="help_read_document">Open content in Smashdocs</div>
                <button class="sd-action-link" tal:attributes="data-url action/url" href="#" tal:content="action/title"/>
                <span tal:replace="structure context/@@authenticator/authenticator"/>
            </form>

            <form class="sd-action" tal:condition="python: action['id'] in ('comment',)">
                <legend i18n:translate="">Comment</legend>
                <div class="sd-help" i18n:translate="help_comment">Open content for commenting Smashdocs</div>
                <button class="sd-action-link" tal:attributes="data-url action/url" href="#" tal:content="action/title"/>
                <span tal:replace="structure context/@@authenticator/authenticator"/>
            </form>

            <form class="sd-action" tal:condition="python: action['id'] == 'edit'">
                <legend i18n:translate="">Edit</legend>
                <div class="sd-help" i18n:translate="help_edit">Open content for editing</div>
                <button class="sd-action-link" tal:attributes="data-url action/url" href="#" tal:content="action/title"/>
                <span tal:replace="structure context/@@authenticator/authenticator"/>
            </form>

            <form class="sd-action" tal:condition="python: action['id'] == 'duplicate'" method="post">
                <legend i18n:translate="">Duplicate</legend>
                <div class="sd-help" i18n:translate="help_duplicate">Create a copy of the current content</div>
                <button class="sd-action-link" tal:attributes="data-url action/url" href="#" tal:content="action/title"/>
                <span tal:replace="structure context/@@authenticator/authenticator"/>
            </form>

            <form class="sd-action" tal:condition="python: action['id'] == 'archive'"
                  method="post" 
                  tal:attributes="action action/url">
                <legend i18n:translate="">Archive</legend>
                <div class="sd-help" i18n:translate="help_archive">Archive current document</div>
                <input type="submit" class="sd-action-link" id="submit-archive" tal:attributes="value action/title"/>
                <span tal:replace="structure context/@@authenticator/authenticator"/>
            </form>

            <form class="sd-action" tal:condition="python: action['id'] == 'unarchive'"
                  method="post" 
                  tal:attributes="action action/url">
                <legend i18n:translate="">Unarchive</legend>
                <div class="sd-help" i18n:translate="help_unarchive">Unarchive current document</div>
                <span tal:replace="structure context/@@authenticator/authenticator"/>
                <input type="submit" class="sd-action-link" id="submit-unarchive" tal:attributes="value action/title"/>
            </form>

        </tal:loop>
    </div>



    <div id="sd-data" tal:condition="python: is_configured and context.document_id">
        <tal:def tal:define="document_info view/document_info">

            <div id="progress">
                <tal:loop repeat="state view/progress_states">
                    <div tal:attributes="class string:sd-circle ${state/css_class}"
                        tal:content="state/title">New</div>
                    <div tal:condition="not: repeat/state/end"
                          class="sd-circle sd-arrow">&rarr;</div>
                </tal:loop>
            </div>

            <hr/>

            <div id="metadata">

                <div class="metadata-row">
                    <span class="metadata-label" i18n:translate="">Your role</span>
                    <span class="metadata-value" tal:content="view/smashdoc_role/capitalize"/>
                </div>
                <div class="metadata-row" tal:condition="document_info">
                    <span class="metadata-label" i18n:translate="">Created</span>
                    <span class="metadata-value" tal:content="python: context.toLocalizedTime(document_info['createdDate'], True)" tal:on-error="nothing"/>
                </div>
                <div class="metadata-row" tal:condition="document_info">
                    <span class="metadata-label" i18n:translate="">Status</span>
                    <span class="metadata-value" tal:content="document_info/status/capitalize"/>
                </div>
                <div class="metadata-row" tal:condition="document_info">
                    <span class="metadata-label" i18n:translate="">Archived</span>
                    <span class="metadata-value" tal:content="document_info/archived"/>
                </div>
                <div class="metadata-row" tal:condition="document_info">
                    <span class="metadata-label" i18n:translate="">Has unread conversation changes</span>
                    <span class="metadata-value" tal:content="document_info/hasUnreadConversationChanges"/>
                </div>
                <div class="metadata-row" tal:condition="document_info">
                    <span class="metadata-label" i18n:translate="">Has unread section changes</span>
                    <span class="metadata-value" tal:content="document_info/hasUnreadSectionChanges"/>
                </div>
            </div>

            <tal:if condition="request/debug | nothing">
                <div tal:condition="context/document_id">
                    <a href="#" id="toggle-document-info" i18n:translate="">Document metadata</a>
                    <table class="listing" id="document-info" style="display: none">
                        <tbody>
                            <tr tal:repeat="k_v python: document_info.items()">
                                <th tal:content="python: k_v[0]"/>
                                <td tal:content="python: k_v[1]"/>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <div>
                    <a href="#" id="toggle-user-info" i18n:translate="">User info</a>
                    <table class="listing" id="user-info" style="display: none">
                        <tbody>
                            <tr> 
                                <th i18n:translate="">Plone User ID</th>
                                <td tal:content="view/user_id"/>
                            </tr>
                            <tr> 
                                <th i18n:translate="">Plone roles</th>
                                <td tal:content="view/plone_roles"/>
                            </tr>
                            <tr> 
                                <th i18n:translate="">Group ID</th>
                                <td tal:content="view/group_id"/>
                            </tr>
                            <tr> 
                                <th i18n:translate="">Smashdocs Role</th>
                                <td tal:content="view/smashdoc_role"/>
                            </tr>
                            <tr> 
                                <th i18n:translate="">Document ID</th>
                                <td tal:content="context/document_id | nothing"/>
                            </tr>
                            <tr> 
                                <th i18n:translate="">Creator ID</th>
                                <td tal:content="context/creator_id | nothing"/>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </tal:if>

            <hr/>

            <table class="listing" id="sd-exports">
                <thead>
                    <tr>
                        <th class="nosort" i18n:translate="">Format </th>
                        <th class="nosort" i18n:translate="">Size</th>
                        <th class="nosort" i18n:translate="">Modified</th>
                        <th class="nosort" tal:condition="not: document_info/archived" i18n:translate="">Action</th>
                    </tr>
                </thead>
                <tbody>
                    <tr tal:repeat="d view/export_formats">
                        <td>
                            <a tal:condition="d/url | nothing"
                               tal:attributes="href d/url"
                               tal:content="d/title | d/format/upper"/>
                            <span  tal:condition="not: d/url | nothing"
                                tal:content="d/title | d/format/upper"/>
                        </td>
                        <td tal:content="d/size_str | nothing"/>
                        <td>
                            <tal:if condition="d/modified | nothing"
                                tal:content="python: context.toLocalizedTime(d['modified'], True)"
                            />
                        <td tal:condition="not: document_info/archived">
                            <a tal:attributes="href string:${context/absolute_url}/${d/generator_url}"
                             i18n:translate="">
                             Generate
                             </a>
                        </td>
                    </tr>
                <(tbody>
            </table>
        </tal:def>
    </div>

    <div style="clear: both"></div>

    <script type="text/javascript">
        $(document).ready(function(){

            $('.sd-action-link').on('click', function() {
                var url = $(this).data('url');
                if (url != null) {
                    window.open(url, '_blank');
                    window.focus();
                    location.reload();
                }
            });

            $('#toggle-document-info').on('click', function() {
                $('#document-info').toggle('fast');
            });

            $('#toggle-user-info').on('click', function() {
                $('#user-info').toggle('fast');
            });
        });
    </script>
</metal:main>

</body>
</html>

