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

    Copyright 2017-2019 MuK IT GmbH
    Copyright 2021 Tecnativa - Víctor Martínez
    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 align-content-start"
                banner_route="/dms/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="__last_update" />
                <!-- <field name="model_name" /> -->
                <templates>
                    <t t-name="kanban-box">
                        <div
                            t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click"
                        >
                            <div class="o_dropdown_kanban dropdown">
                                <a
                                    class="dropdown-toggle o-no-caret btn"
                                    href="#"
                                    role="button"
                                    data-toggle="dropdown"
                                    aria-label="Dropdown menu"
                                    title="Dropdown menu"
                                >
                                    <span class="fa fa-ellipsis-v" />
                                </a>
                                <div class="dropdown-menu" role="menu">
                                    <div class="row">
                                        <div class="col-6 mk_file_kanban_operations">
                                            <h6 class="dropdown-header">
                                                Operations
                                            </h6>
                                            <a
                                                t-if="record.permission_write.raw_value and !record.is_locked.raw_value"
                                                role="menuitem"
                                                name="lock"
                                                type="object"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-lock" />
                                                Lock
                                            </a>
                                            <a
                                                t-if="record.is_locked.raw_value  and record.is_lock_editor.raw_value"
                                                role="menuitem"
                                                name="unlock"
                                                type="object"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-unlock-alt" />
                                                Unlock
                                            </a>
                                            <a
                                                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))"
                                                role="menuitem"
                                                name="toggle_active"
                                                type="object"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-archive" />
                                                Archive
                                            </a>
                                            <a
                                                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))"
                                                role="menuitem"
                                                name="toggle_active"
                                                type="object"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-archive" />
                                                Unarchive
                                            </a>
                                            <a
                                                role="menuitem"
                                                class="dropdown-item"
                                                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
                                            class="col-6 border-left mk_file_kanban_actions"
                                        >
                                            <h6 class="dropdown-header">
                                                Actions
                                            </h6>
                                            <a
                                                role="menuitem"
                                                type="open"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-external-link" />
                                                Open
                                            </a>
                                            <a
                                                t-if="record.permission_write.raw_value"
                                                role="menuitem"
                                                type="edit"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-pencil-square-o" />
                                                Edit
                                            </a>
                                            <a
                                                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))"
                                                role="menuitem"
                                                type="delete"
                                                class="dropdown-item"
                                            >
                                                <i class="fa fa-trash-o" />
                                                Delete
                                            </a>
                                        </div>
                                    </div>
                                    <div
                                        t-if="record.permission_write.raw_value"
                                        class="row"
                                    >
                                        <div role="menuitem" class="col-12">
                                            <ul
                                                class="oe_kanban_colorpicker"
                                                data-field="color"
                                            />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="oe_kanban_content">
                                <div class="o_kanban_image">
                                    <div class="o_kanban_image_wrapper">
                                        <a
                                            class="o_kanban_dms_file_preview"
                                            t-att-data-id="record.id"
                                            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>
                                <div class="o_kanban_details">
                                    <div class="o_kanban_details_wrapper">
                                        <div
                                            class="o_kanban_record_title o_text_overflow"
                                        >
                                            <field name="name" />
                                        </div>
                                        <div class="o_kanban_record_body">
                                            <field
                                                name="tag_ids"
                                                widget="many2many_tags"
                                                options="{'color_field': 'color'}"
                                            />
                                        </div>
                                        <div class="o_kanban_record_bottom">
                                            <div class="oe_kanban_bottom_left">
                                                <field
                                                    name="write_date"
                                                    widget="date"
                                                />
                                            </div>
                                            <div class="oe_kanban_bottom_right">
                                                <span
                                                    t-if="record.is_locked.raw_value"
                                                    class="mk_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>
                        </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</attribute>
            </kanban>
            <xpath expr="//div[hasclass('o_dropdown_kanban')]" position="replace" />
            <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" invisible="1" />
                <field name="is_locked" invisible="1" />
                <field name="is_lock_editor" 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" 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"
                        attrs="{'invisible':['|',('is_locked', '!=', False),('permission_write', '=', False)]}"
                    />
                    <button
                        class="oe_highlight"
                        name="unlock"
                        type="object"
                        string="Unlock"
                        attrs="{'invisible':['|',('is_locked', '=', False),('is_lock_editor', '=', False)]}"
                    />
                </header>
                <sheet>
                    <widget
                        name="web_ribbon"
                        title="Archived"
                        bg_color="bg-danger"
                        attrs="{'invisible': [('active', '=', True)]}"
                    />
                    <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}"
                                attrs="{'invisible': ['|', ('name', '=', False), ('directory_id', '=', False)]}"
                            />
                        </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"
                            attrs="{'invisible': [('storage_id_save_type', '!=', 'attachment')]}"
                        />
                        <field
                            name="res_id"
                            readonly="True"
                            attrs="{'invisible': [('storage_id_save_type', '!=', 'attachment')]}"
                        />
                        <field
                            name="record_ref"
                            attrs="{'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>
    <menuitem
        id="menu_dms_file"
        name="Files"
        sequence="20"
        parent="main_menu_dms"
        action="action_dms_file"
    />
    <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" invisible="1" />
                <field name="is_lock_editor" 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>
    <menuitem
        id="menu_dms_file_migration"
        name="Migration"
        parent="cat_menu_dms_config_system"
        action="action_dms_file_migration"
        sequence="8"
    />
    <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>
