<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">

    <script>
        window.__define = window.define;
        window.__require = window.require;
        window.define = undefined;
        window.require = undefined;
    </script>
    <script type="text/javascript" tal:attributes="src string:$portal_url/++resource++zopyx.plone.smashdocs/moment-with-locales.js"></script>
    <script>
        window.define = window.__define;
        window.require = window.__require;
        window.__define = undefined;
        window.__require = undefined;
    </script>

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

    <div style="margin-bottom: 1em">
        <span class="label" i18n:translate="">Group ID</span>:
        <span tal:content="context/group_id | nothing" />
    </div>

    <a tal:attributes="href string:${context/absolute_url}/++add++SmashDocument">
        <button i18n:translate="">New document</button>
    </a>
    <br/>
    <br/>

    <tal:loop repeat="mode python: ('draft', 'review')">

        <tal:def define="rows python: view.get_documents(mode)">

            <table class="listing documents" tal:condition="rows">
                <caption>
                    <span i18n:translate="" tal:content="mode"/>
                    (<span tal:content="python: len(rows)"/>)
                <thead>
                    <tr>
                        <th i18n:translate="">Title</th>
                        <th i18n:translate="">Status</th>
                        <th i18n:translate="">Created</th>
                        <th i18n:translate="">Creator</th>
                        <th i18n:translate="">Group</th>
                        <th i18n:translate="">Tags</th>
                        <th i18n:translate="">Archived</th>
                        <th class="checkmark" i18n:translate="">Unread conversation changes</th>
                        <th class="checkmark" i18n:translate="">Unread section changes</th>
                        <th class="checkmark" i18n:translate="">Documents opened</th>
                    </tr>
                </thead>
                <tbody>
                    <tr tal:repeat="row rows">
                        <td>
                            <a tal:attributes="href string:${context/absolute_url}/redirect-document?document_id=${row/id}" tal:content="row/title"/>
                            <br/>
                            <!--
                            <a tal:condition="python: mode=='draft'"
                                tal:attributes="href string:${context/absolute_url}/delete-document?document_id=${row/id}">
                                Delete
                            </a>
                            -->
                        </td>
                        <td i18n:translate="" tal:content="python: row['status']"/>
                        <td>
                            <span tal:attributes="data-time python: int(row['createdDate'])" tal:content="row/createdDate"/>
                        </td>
                        <td i18n:translate="" tal:content="python: row['creatorId']"/>
                        <td i18n:translate="" tal:content="python: row['groupId']"/>
                        <td tal:content="python: u', '.join(sorted(row['tags']))"/>
                        <td i18n:translate="" tal:content="python: str(row['archived'])"/>
                        <td>
                            <span tal:attributes="class python: 'status-nok' if row['hasUnreadConversationChanges'] else 'status-ok'"></span>
                        </td>
                        <td>
                            <span td tal:attributes="class python: 'status-nok' if row['hasUnreadSectionChanges'] else 'status-ok'"></span>
                        </td>
                        <td>
                            <span tal:attributes="class python: 'status-nok' if row['hasOpenedDocument'] else 'status-ok'"></span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </tal:def>
    </tal:loop>

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

            $('span[data-time]').each(function() {
                var dt = $(this).data('time');
                var lang = $('html').attr('lang');
                moment.locale(lang);
                var m = moment.unix(dt);
                $(this).text(m.fromNow());
            });
        });
    </script>
</metal:main>

</body>
</html>

