<?xml version="1.0" encoding="UTF-8" ?>
<!--

    Copyright 2017-2019 MuK IT GmbH
    Copyright 2021 Tecnativa - Víctor Martínez
    Copyright 2024 Subteno - Timothée Vannier (https://www.subteno.com).
    License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

  -->
<odoo>
    <record id="search_dms_file" model="ir.ui.view">
        <field name="name">dms_file.search</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <search>
                <field name="name" filter_domain="[('name','ilike',self)]" />
                <filter
                    string="All Files"
                    name="all"
                    domain="['|',('active', '=',  False), ('active', '!=',  False)]"
                />
                <filter
                    string="My Files"
                    name="filter_user"
                    domain="[('create_uid', '=', uid)]"
                />
                <separator />
                <filter
                    string="Archived Files"
                    name="filter_active"
                    domain="[('active', '=', False)]"
                />
                <separator />
                <filter
                    string="Creation Date"
                    name="filter_create"
                    date="create_date"
                />
                <filter
                    string="Modification Date"
                    name="filter_write"
                    date="write_date"
                />
                <group expand="0" string="Group By">
                    <filter
                        name="group_color"
                        string="Color"
                        domain="[]"
                        context="{'group_by':'color'}"
                    />
                    <filter
                        name="group_category"
                        string="Category"
                        domain="[]"
                        context="{'group_by':'category_id'}"
                    />
                    <separator />
                    <filter
                        name="group_storage"
                        string="Storage"
                        domain="[]"
                        context="{'group_by':'storage_id'}"
                    />
                    <filter
                        name="group_directory"
                        string="Directories"
                        domain="[]"
                        context="{'group_by':'directory_id'}"
                    />
                </group>
                <searchpanel>
                    <field
                        name="directory_id"
                        icon="fa-folder"
                        limit="0"
                        enable_counters="1"
                    />
                    <field
                        name="category_id"
                        icon="fa-users"
                        limit="0"
                        enable_counters="1"
                    />
                </searchpanel>
            </search>
        </field>
    </record>
    <record id="view_dms_file_kanban" model="ir.ui.view">
        <field name="name">dms_file.kanban</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <kanban
                js_class="file_kanban"
                class="mk_file_kanban_view o_kanban_small_column o_kanban_mobile"
                banner_route="/onboarding/document_onboarding_file"
            >
                <field name="id" />
                <field name="tag_ids" />
                <field name="name" />
                <field name="color" />
                <field name="active" />
                <field name="mimetype" />
                <field name="icon_url" />
                <field name="create_uid" />
                <field name="write_date" />
                <field name="locked_by" />
                <field name="is_locked" />
                <field name="is_lock_editor" />
                <field name="permission_write" />
                <field name="permission_unlink" />
                <field name="write_date" />
                <templates>
                    <t t-name="kanban-menu">
                        <div class="container">
                            <div class="row">
                                <div
                                    class="col-6 o_kanban_card_manage_section o_kanban_manage_view"
                                >
                                    <h5
                                        role="menuitem"
                                        class="o_kanban_card_manage_title"
                                    >
                                        <span>Operations</span>
                                    </h5>
                                    <div
                                        role="menuitem"
                                        t-if="record.permission_write.raw_value and !record.is_locked.raw_value"
                                    >
                                        <a name="lock" type="object">
                                            <i class="fa fa-lock" />
                                            Lock
                                        </a>
                                    </div>
                                    <div
                                        role="menuitem"
                                        t-if="record.is_locked.raw_value  and record.is_lock_editor.raw_value"
                                    >
                                        <a name="unlock" type="object">
                                            <i class="fa fa-unlock-alt" />
                                            Unlock
                                        </a>
                                    </div>
                                    <div
                                        role="menuitem"
                                        t-if="record.permission_write.raw_value and record.active.raw_value and (!record.is_locked.raw_value or (record.is_locked.raw_value and record.is_lock_editor.raw_value))"
                                    >
                                        <a name="toggle_active" type="object">
                                            <i class="fa fa-archive" />
                                            Archive
                                        </a>
                                    </div>
                                    <div
                                        role="menuitem"
                                        t-if="record.permission_write.raw_value and !record.active.raw_value and (!record.is_locked.raw_value or (record.is_locked.raw_value and record.is_lock_editor.raw_value))"
                                    >
                                        <a name="toggle_active" type="object">
                                            <i class="fa fa-archive" />
                                            Unarchive
                                        </a>
                                    </div>
                                    <div role="menuitem">
                                        <a
                                            t-attf-href="/web/content?id=#{record.id.raw_value}&amp;field=content&amp;model=dms.file&amp;filename_field=name&amp;download=true"
                                        >
                                            <i class="fa fa-download" />
                                            Download
                                        </a>
                                    </div>
                                </div>
                                <div class="col-6 o_kanban_card_manage_section">
                                    <h5
                                        role="menuitem"
                                        class="o_kanban_card_manage_title"
                                    >
                                        <span>Actions</span>
                                    </h5>
                                    <div role="menuitem">
                                        <a type="open">
                                            <i class="fa fa-external-link" />
                                            Open
                                        </a>
                                    </div>
                                    <div
                                        role="menuitem"
                                        t-if="record.permission_write.raw_value"
                                    >
                                        <a type="edit">
                                            <i class="fa fa-pencil-square-o" />
                                            Edit
                                        </a>
                                    </div>
                                    <div
                                        role="menuitem"
                                        t-if="record.permission_unlink.raw_value and (!record.is_locked.raw_value or (record.is_locked.raw_value and record.is_lock_editor.raw_value))"
                                    >
                                        <a type="delete">
                                            <i class="fa fa-trash-o" />
                                            Delete
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div class="o_kanban_card_manage_settings row">
                                <div
                                    t-if="record.permission_write.raw_value"
                                    role="menuitem"
                                    aria-haspopup="true"
                                >
                                    <ul
                                        class="oe_kanban_colorpicker"
                                        data-field="color"
                                        role="popup"
                                    />
                                </div>
                            </div>
                        </div>
                    </t>
                    <t t-name="kanban-box">
                        <div
                            t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click oe_kanban_content oe_kanban_card row g-0"
                        >
                            <div class="col-3 h-100">
                                <a
                                    class="h-100 d-block o_kanban_dms_file_preview"
                                    t-att-data-id="record.id.raw_value"
                                    t-att-id="record.id.raw_value"
                                    t-att-name="record.name.raw_value"
                                >
                                    <img
                                        t-att-src="record.icon_url.raw_value"
                                        alt="Icon"
                                    />
                                </a>
                            </div>
                            <div class="col-9">
                                <div class="o_kanban_details">
                                    <h5 class="o_kanban_record_title o_text_overflow">
                                        <field name="name" />
                                    </h5>
                                    <div class="o_kanban_record_body">
                                        <field
                                            name="tag_ids"
                                            widget="many2many_tags"
                                            options="{'color_field': 'color'}"
                                        />
                                        <field name="write_date" widget="date" />
                                    </div>
                                    <div class="o_kanban_record_bottom">
                                        <div class="oe_kanban_bottom_right">
                                            <span
                                                t-if="record.is_locked.raw_value"
                                                class="o_dms_file_kanban_lock"
                                            >
                                                <i
                                                    t-attf-class="fa #{(record.is_locked.raw_value and !record.is_lock_editor.raw_value) ? 'fa-lock' : ''} #{((record.is_locked.raw_value and record.is_lock_editor.raw_value)) ? 'fa-unlock-alt' : ''}"
                                                    t-att-title="record.locked_by.value"
                                                />
                                            </span>
                                            <img
                                                t-att-src="kanban_image('res.users', 'image_128', record.create_uid.raw_value)"
                                                t-att-alt="record.create_uid.value"
                                                class="oe_kanban_avatar"
                                            />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>
    <!-- Base view that can be overwritten by other modules as needed !-->
    <record id="view_dms_file_kanban_wizard_selection" model="ir.ui.view">
        <field name="name">dms_file.kanban.wizard.selection</field>
        <field name="model">dms.file</field>
        <field name="inherit_id" ref="dms.view_dms_file_kanban" />
        <field name="priority">9999</field>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <kanban position="attributes">
                <attribute name="banner_route" />
                <attribute name="class">o_kanban_mobile mk_file_kanban_view</attribute>
            </kanban>
            <xpath expr="//div[hasclass('oe_kanban_bottom_right')]" position="replace">
                <div class="oe_kanban_bottom_right" />
            </xpath>
        </field>
    </record>
    <record id="view_dms_file_tree" model="ir.ui.view">
        <field name="name">dms_file.tree</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <tree
                js_class="file_list"
                decoration-warning="not active"
                decoration-muted="(is_locked and not is_lock_editor)"
                multi_edit="1"
                default_order="name asc"
            >
                <field name="active" column_invisible="1" />
                <field name="is_locked" column_invisible="1" />
                <field name="is_lock_editor" column_invisible="1" />
                <field name="name" />
                <field name="directory_id" optional="hide" />
                <field name="root_directory_id" optional="hide" />
                <field name="write_date" />
                <field name="human_size" string="Size" />
                <field name="mimetype" />
                <field name="category_id" column_invisible="1" />
                <field
                    name="tag_ids"
                    widget="many2many_tags"
                    options="{'color_field': 'color', 'no_create_edit': True}"
                />
            </tree>
        </field>
    </record>
    <record id="view_dms_file_graph" model="ir.ui.view">
        <field name="name">dms_file.graph</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <graph type="pie">
                <field name="directory_id" type="row" />
                <field name="size" type="measure" />
            </graph>
        </field>
    </record>
    <record id="view_dms_file_pivot" model="ir.ui.view">
        <field name="name">dms_file.pivot</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <pivot display_quantity="true">
                <field name="storage_id" type="row" />
                <field name="directory_id" type="row" />
                <field name="size" type="measure" />
            </pivot>
        </field>
    </record>
    <record id="view_dms_file_form" model="ir.ui.view">
        <field name="name">dms_file.form</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <form string="Files">
                <header>
                    <button
                        class="oe_highlight"
                        name="lock"
                        type="object"
                        string="Lock"
                        invisible="is_locked or not permission_write"
                    />
                    <button
                        class="oe_highlight"
                        name="unlock"
                        type="object"
                        string="Unlock"
                        invisible="not is_locked or not is_lock_editor"
                    />
                </header>
                <sheet>
                    <!-- locked ribbon first, so that archived ribbon appear above if archived-->
                    <widget
                        name="web_ribbon"
                        title="Locked"
                        bg_color="text-bg-info"
                        invisible="not is_locked or (is_locked and locked_by != uid)"
                    />
                    <widget
                        name="web_ribbon"
                        title="Locked"
                        bg_color="text-bg-warning"
                        invisible="not is_locked or (is_locked and locked_by == uid)"
                    />
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        invisible="active"
                    />
                    <div class="oe_button_box" name="button_box" />
                    <field
                        name="image_1920"
                        widget="image"
                        class="oe_avatar"
                        nolabel="1"
                        options="{'image_preview': 'image_128'}"
                    />
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only" />
                        <h1>
                            <field name="name" />
                            <field name="active" invisible="1" />
                        </h1>
                        <h4>
                            <field
                                name="path_json"
                                widget="path_json"
                                options="{'prefix': True, 'suffix': False}"
                                invisible="not name or not directory_id"
                            />
                        </h4>
                    </div>
                    <group name="content">
                        <group>
                            <field
                                name="content"
                                filename="name"
                                mimetype="mimetype"
                                widget="preview_binary"
                            />
                        </group>
                        <group>
                            <field name="extension" />
                            <field name="mimetype" />
                        </group>
                    </group>
                    <group name="settings">
                        <group>
                            <field
                                name="directory_id"
                                options="{'no_quick_create': True}"
                            />
                            <field
                                name="storage_id"
                                options="{'no_open': True}"
                                groups="!dms.group_dms_manager"
                            />
                            <field name="storage_id" groups="dms.group_dms_manager" />
                        </group>
                        <group>
                            <field
                                name="category_id"
                                placeholder="Internal / Human Resource"
                                options="{'no_open': True, 'no_create': True}"
                            />
                            <field
                                name="tag_ids"
                                widget="many2many_tags"
                                placeholder="Tags..."
                                options="{'color_field': 'color', 'no_create_edit': True}"
                            />
                        </group>
                    </group>
                    <group>
                        <field name="storage_id_save_type" invisible="True" />
                        <field
                            name="res_model"
                            readonly="True"
                            invisible="storage_id_save_type != 'attachment'"
                        />
                        <field
                            name="res_id"
                            readonly="True"
                            invisible="storage_id_save_type != 'attachment'"
                        />
                        <field
                            name="record_ref"
                            invisible="storage_id_save_type != 'attachment'"
                        />
                    </group>
                    <notebook>
                        <page name="page_meta" string="Meta Information">
                            <group>
                                <group>
                                    <field name="create_date" readonly="1" />
                                    <field name="create_uid" readonly="1" />
                                </group>
                                <group>
                                    <field name="write_date" readonly="1" />
                                    <field name="write_uid" readonly="1" />
                                </group>
                            </group>
                        </page>
                        <page name="page_access" string="Access Information">
                            <group>
                                <group>
                                    <field name="permission_write" readonly="1" />
                                    <field name="permission_unlink" readonly="1" />
                                </group>
                                <group>
                                    <field name="is_lock_editor" invisible="1" />
                                    <field name="is_locked" invisible="1" />
                                    <field name="locked_by" />
                                </group>
                            </group>
                        </page>
                        <page
                            name="page_technical"
                            string="Technical Information"
                            invisible="1"
                            groups="dms.group_dms_manager,base.group_no_one"
                        >
                            <group name="technical">
                                <group name="technical_left">
                                </group>
                                <group name="technical_right">
                                </group>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" />
                    <field name="activity_ids" />
                    <field name="message_ids" />
                </div>
            </form>
        </field>
    </record>
    <record id="action_dms_file" model="ir.actions.act_window">
        <field name="name">Files</field>
        <field name="res_model">dms.file</field>
        <field name="view_mode">kanban,tree,graph,pivot,form</field>
        <field name="domain">[("is_hidden", "=", False)]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Add a new File.
            </p>
            <p>
                Files are used to save content directly in Odoo.
            </p>
        </field>
    </record>
    <!-- Base action to be called when a file selector is to be used !-->
    <record id="action_dms_file_wizard_selector" model="ir.actions.act_window">
        <field name="name">Files</field>
        <field name="res_model">dms.file</field>
        <field name="target">new</field>
        <field name="view_mode">kanban</field>
        <field name="context">{'create': False}</field>
        <field
            name="view_ids"
            eval="[(5, 0, 0),(0, 0, {'view_mode': 'kanban', 'view_id': ref('view_dms_file_kanban_wizard_selection')})]"
        />
    </record>
    <record id="search_dms_file_migration" model="ir.ui.view">
        <field name="name">dms_file.search</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <search>
                <field name="name" filter_domain="[('name','ilike',self)]" />
                <group expand="0" string="Group By">
                    <filter
                        name="group_storage"
                        string="Storage"
                        domain="[]"
                        context="{'group_by':'storage_id'}"
                    />
                </group>
                <searchpanel>
                    <field
                        name="directory_id"
                        icon="fa-folder"
                        limit="0"
                        enable_counters="1"
                    />
                    <field
                        name="category_id"
                        icon="fa-users"
                        limit="0"
                        enable_counters="1"
                    />
                </searchpanel>
            </search>
        </field>
    </record>
    <record id="view_dms_file_migration_tree" model="ir.ui.view">
        <field name="name">dms_file.tree</field>
        <field name="model">dms.file</field>
        <field name="arch" type="xml">
            <tree
                decoration-muted="(is_locked and not is_lock_editor)"
                create="0"
                delete="0"
            >
                <field name="is_locked" column_invisible="1" />
                <field name="is_lock_editor" column_invisible="1" />
                <field name="name" />
                <field name="write_date" />
                <field name="human_size" string="Size" />
                <field name="mimetype" />
                <field name="storage_id" />
                <field name="migration" />
            </tree>
        </field>
    </record>
    <record id="action_dms_file_migration" model="ir.actions.act_window">
        <field name="name">Files</field>
        <field name="res_model">dms.file</field>
        <field name="view_mode">tree</field>
        <field name="search_view_id" ref="search_dms_file_migration" />
        <field
            name="domain"
        >[('require_migration', '=', True), '|', ('active', '=', False), ('active', '!=', False)]
        </field>
        <field name="context">{'search_default_group_storage': 1}</field>
        <field
            name="view_ids"
            eval="[(5, 0, 0), (0, 0, {'view_mode': 'tree', 'view_id': ref('view_dms_file_migration_tree')})]"
        />
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Add a new File.
            </p>
            <p>
                Files are used to save content directly in Odoo.
            </p>
        </field>
    </record>
    <record id="view_dms_file_new_form" model="ir.ui.view">
        <field name="name">dms_file.form</field>
        <field name="model">dms.file</field>
        <field name="inherit_id" ref="view_dms_file_form" />
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <xpath expr="//header" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            <xpath expr="//sheet//div[hasclass('oe_button_box')]" position="attributes">
                <attribute name="invisible">1</attribute>
            </xpath>
            <form position="inside">
                <footer>
                    <button
                        class="btn btn-primary"
                        type="object"
                        string="Create"
                        name="action_save_onboarding_file_step"
                    />
                    <button special="cancel" string="Cancel" />
                </footer>
            </form>
        </field>
    </record>
    <record id="action_dms_file_new" model="ir.actions.act_window">
        <field name="name">New Root Directory</field>
        <field name="res_model">dms.file</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
        <field name="view_id" ref="view_dms_file_new_form" />
    </record>
    <record id="action_wizard_dms_file_move" model="ir.actions.server">
        <field name="name">Move</field>
        <field name="model_id" ref="dms.model_dms_file" />
        <field name="binding_model_id" ref="dms.model_dms_file" />
        <field name="groups_id" eval="[(4, ref('dms.group_dms_user'))]" />
        <field name="binding_view_types">list</field>
        <field name="state">code</field>
        <field name="code">
            action = model.action_wizard_dms_file_move()
        </field>
    </record>

</odoo>
