<?xml version="1.0" encoding="UTF-8" ?>
<!--
    Copyright 2024 Subteno - Timothée Vannier (https://www.subteno.com).
    License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
-->
<odoo>
    <template
        id="portal_my_home_dms"
        name="Portal My Home : dms entries"
        inherit_id="portal.portal_my_home"
        priority="20"
    >
        <xpath expr="//div[@id='portal_client_category']" position="after">
            <div class="o_portal_dms row g-2 mt-3" id="portal_dms_category">
                <t t-call="portal.portal_docs_entry">
                    <t t-set="title">Documents</t>
                    <t t-set="text" t-value="'Manage your documents'" />
                    <t t-set="url" t-value="'/my/dms'" />
                    <t
                        t-set="icon"
                        t-value="'/dms/static/description/portal_icon.svg'"
                    />
                    <t t-set="placeholder_count" t-value="'dms_directory_count'" />
                </t>
            </div>
        </xpath>
    </template>
    <template
        id="portal_my_dms_breadcrumbs"
        name="My DMS: Breadcrumbs"
        inherit_id="portal.portal_breadcrumbs"
    >
        <xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
            <t t-if="page_name == 'dms_directory'">
                <t t-if="not access_token">
                    <li class="breadcrumb-item">
                        <t t-if="dms_directory">
                            <a href="/my/dms" title="DMS">Documents</a>
                        </t>
                        <t t-if="not dms_directory">
                            <span>Documents</span>
                        </t>
                    </li>
                </t>
                <t t-foreach="dms_parent_categories" t-as="dms_parent_category">
                    <li class="breadcrumb-item">
                        <t t-if="dms_parent_category.id != dms_directory.id">
                            <a
                                t-attf-href="/my/dms/directory/#{dms_parent_category.id}?{{ keep_query() }}"
                                t-att-title="dms_parent_category.name"
                            >
                                <span t-esc="dms_parent_category.name" />
                            </a>
                        </t>
                        <t t-if="dms_parent_category.id == dms_directory.id">
                            <span t-esc="dms_parent_category.name" />
                        </t>
                    </li>
                </t>
            </t>
        </xpath>
    </template>
    <template id="portal_my_dms" name="My DMS">
        <t t-call="portal.portal_layout">
            <t t-set="breadcrumbs_searchbar" t-value="True" />
            <t t-call="portal.portal_searchbar" />
            <t t-if="not dms_directories and not dms_files">
                <div class="alert alert-warning mt8" role="alert">Not results</div>
            </t>
            <t t-if="dms_directories or dms_files" t-call="portal.portal_table">
                <thead>
                    <tr class="active">
                        <th>Name</th>
                        <th>Size</th>
                        <th>Last update</th>
                    </tr>
                </thead>
                <tbody>
                    <t t-foreach="dms_directories" t-as="dms_directory">
                        <tr class="tr_dms_directory">
                            <td>
                                <a
                                    t-attf-href="/my/dms/directory/#{dms_directory.id}?{{ keep_query() }}"
                                    t-attf-class="tr_dms_directory_link"
                                    t-att-title="dms_directory.name"
                                >
                                    <img
                                        class="o_portal_contact_img"
                                        t-att-src="dms_directory.icon_url"
                                    />
                                    <span t-esc="dms_directory.name" />
                                </a>
                            </td>
                            <td>
                                <span t-esc="dms_directory.count_elements" /> element(s)
                            </td>
                            <td>
                                <span
                                    t-esc="dms_directory.write_date"
                                    t-options="{'widget': 'date'}"
                                />
                            </td>
                        </tr>
                    </t>
                    <t t-if="dms_files">
                        <t t-foreach="dms_files" t-as="dms_file">
                            <tr class="tr_dms_file">
                                <td>
                                    <a
                                        t-attf-href="/my/dms/file/#{dms_file.id}/download?{{ keep_query() }}"
                                        t-attf-class="tr_dms_file_link"
                                        t-att-title="dms_file.name"
                                    >
                                        <img
                                            class="o_portal_contact_img"
                                            t-att-src="dms_file.icon_url + (('&amp;access_token=' + access_token) if access_token else '')"
                                        />
                                            <span t-esc="dms_file.name" />
                                    </a>
                                </td>
                                <td>
                                    <span t-esc="dms_file.get_human_size()" />
                                </td>
                                <td>
                                    <span
                                        t-esc="dms_file.write_date"
                                        t-options="{'widget': 'date'}"
                                    />
                                </td>
                            </tr>
                        </t>
                    </t>
                </tbody>
            </t>
        </t>
    </template>
</odoo>
