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

<!--

    Copyright (c) 2017-2019 MuK IT GmbH.

    This file is part of MuK Documents 
    (see https://mukit.at).

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.

  -->

<odoo>

<record id="search_dms_file" model="ir.ui.view">
	<field name="name">muk_dms_file.search</field>
	<field name="model">muk_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'}" />
				<separator/>
				<filter name="group_storage" string="Storage" domain="[]" context="{'group_by':'storage'}" />
				<filter name="group_directory" string="Directories" domain="[]" context="{'group_by':'directory'}" />
			</group>
		</search>
	</field>
</record>

<record id="view_dms_file_kanban" model="ir.ui.view">
	<field name="name">muk_dms_file.kanban</field>
	<field name="model">muk_dms.file</field>
	<field name="arch" type="xml">
		<kanban class="mk_file_kanban_view o_kanban_small_column align-content-start" 
				banner_route="/dms/document_onboarding/file" js_class="file_kanban">
			<field name="id" />
			<field name="tags"/>
			<field name="name" />
			<field name="color"/>
			<field name="active"/>
            <field name="mimetype"/>
            <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" />
			<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.permission_write.raw_value and 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" 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" 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=muk_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" 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">
									<img t-att-src="kanban_image('muk_dms.file', 'thumbnail_medium', record.id.raw_value)" alt="Thumbnail"/>
								</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="tags" 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_small', record.create_uid.raw_value)" 
												t-att-alt="record.create_uid.value" class="oe_kanban_avatar"/>
									    </div>
									</div>
								</div>
                            </div>
						</div> 
					</div>
				</t>
			</templates>
            <searchpanel>
                <field name="directory" domain="[['is_hidden', '=', False]]" icon="fa-folder"/>
                <field name="directory" string="Starred"  domain="[['is_hidden', '=', False], ['starred', '=', True]]" select="multi" icon="fa-star"/>
                <field name="tags" select="multi" icon="fa-tag" groupby="category" />
            </searchpanel>
		</kanban>
	</field>
</record>

<record id="view_dms_file_tree" model="ir.ui.view">
	<field name="name">muk_dms_file.tree</field>
	<field name="model">muk_dms.file</field>
	<field name="arch" type="xml">
		<tree string="Files" js_class="file_list" decoration-warning="not active"
				decoration-muted="(is_locked and not is_lock_editor)" >
			<field name="active" invisible="1"/>
			<field name="is_locked" invisible="1"/>
			<field name="is_lock_editor" invisible="1"/>
			<field name="name" />
			<field name="write_date" />
			<field name="size" widget="binary_size" />
			<field name="mimetype" />
			<field name="path_names" widget="path_names" string="Path" />
		</tree>
	</field>
</record>

<record id="view_dms_file_graph" model="ir.ui.view">
	<field name="name">muk_dms_file.graph</field>
	<field name="model">muk_dms.file</field>
	<field name="arch" type="xml">
		<graph type="pie" >
			<field name="directory" type="row" />
			<field name="size" type="measure" />
		</graph>
	</field>
</record>

<record id="view_dms_file_pivot" model="ir.ui.view">
	<field name="name">muk_dms_file.pivot</field>
	<field name="model">muk_dms.file</field>
	<field name="arch" type="xml">
		<pivot display_quantity="true" >
			<field name="storage" type="row" />
			<field name="directory" type="row" />
			<field name="size" type="measure" widget="binary_size" />
		</pivot>
	</field>
</record>

<record id="view_dms_file_form" model="ir.ui.view">
	<field name="name">muk_dms_file.form</field>
	<field name="model">muk_dms.file</field>
	<field name="arch" type="xml">
		<form string="Files" js_class="file_form">
			<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>
			<div class="alert alert-warning text-center o_form_header" attrs="{'invisible': [('is_locked', '!=', True)]}" role="status">
         		<strong>This file is locked!</strong>
      		</div>
			<sheet>
				<div class="oe_button_box" name="button_box">
					<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive">
                    	<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
                    </button>
                </div>
				<field name="thumbnail" widget="image" class="oe_avatar oe_read_only" 
                	options="{'preview_image': 'thumbnail_medium', 'size': [90, 90]}" />
				<field name="custom_thumbnail" widget="image" class="oe_avatar oe_edit_only" 
					options="{'preview_image': 'custom_thumbnail_medium', 'size': [90, 90]}" />
				<div class="oe_title">
					<label for="name" class="oe_edit_only" />
					<h1>
						<field name="name" />
					</h1>
					<h4>
 						<field name="path_json" widget="path_json" options="{'prefix': True, 'suffix': False}" />
					</h4>
				</div>
				<group name="content">
					<group>
						<field name="content" filename="name" />
						<field name="size" widget="binary_size" />
					</group>
					<group>
						<field name="extension" />
						<field name="mimetype" />
					</group>
				</group>
				<group name="settings">
					<group>
						<field name="directory" options="{'no_quick_create': True}" />
						<field name="storage" options="{'no_open': True}"/>
					</group>
					<group>
 						<field name="category" placeholder="Internal / Human Resource"
 							options="{'no_open': True, 'no_create': True}" />
						<field name="tags" widget="many2many_tags" placeholder="Tags..."
 							options="{'color_field': 'color', 'no_create_edit': True}" />
					</group>
				</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="muk_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>
		</form>
	</field>
</record>

<record id="view_dms_file_manager_form" model="ir.ui.view">
	<field name="name">muk_dms_file.form</field>
	<field name="model">muk_dms.file</field>
	<field name="inherit_id" ref="view_dms_file_form" />
    <field name="groups_id" eval="[(6, 0, [ref('muk_dms.group_dms_manager')])]"/>
	<field name="arch" type="xml">
		<field name="storage" position="attributes">
	 		<attribute name="options">{}</attribute>
		</field>
    </field>
</record>

<record id="action_dms_file" model="ir.actions.act_window">
	<field name="name">Files</field>
	<field name="res_model">muk_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>

<menuitem id="menu_dms_file" name="Files" sequence="20"
	parent="main_menu_muk_dms" action="action_dms_file" />
	
<record id="search_dms_file_migration" model="ir.ui.view">
	<field name="name">muk_dms_file.search</field>
	<field name="model">muk_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'}" />
			</group>
		</search>
	</field>
</record>

<record id="view_dms_file_migration_tree" model="ir.ui.view">
	<field name="name">muk_dms_file.tree</field>
	<field name="model">muk_dms.file</field>
	<field name="arch" type="xml">
		<tree string="Files" decoration-muted="(is_locked and not is_lock_editor)">
			<field name="is_locked" invisible="1"/>
			<field name="is_lock_editor" invisible="1"/>
			<field name="name" />
			<field name="write_date" />
			<field name="size" widget="binary_size" />
			<field name="mimetype" />
			<field name="storage" />
			<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">muk_dms.file</field>
	<field name="view_mode">tree</field>
	<field name="search_view_id" ref="search_dms_file_migration"/>
	<field name="domain">['|',('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_muk_dms_config_system" 
	action="action_dms_file_migration"
	sequence="8" />

<record id="view_dms_file_new_form" model="ir.ui.view">
	<field name="name">muk_dms_file.form</field>
	<field name="model">muk_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="replace" />
		<xpath expr="//sheet//div[hasclass('oe_button_box')]" position="replace" />
		<form position="inside">
	        <footer position="replace">
	            <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">muk_dms.file</field>
	<field name="view_mode">form</field>
    <field name="view_type">form</field>
	<field name="target">new</field>
    <field name="view_id" ref="view_dms_file_new_form" />
</record>

</odoo>
