<?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="action_dms_directories_storage" model="ir.actions.act_window">
    <field name="name">Directories</field>
    <field name="view_type">form</field>
	<field name="res_model">muk_dms.directory</field>
	<field name="view_mode">kanban,tree,form</field>
	<field name="domain">
		[
			("storage", "=",  active_id),
			("is_hidden", "=",  False),
		]
	</field>
	<field name="context">
		{
			'default_root_storage': active_id,
			'default_is_root_directory': True,
		}
    </field>
	<field name="help" type="html">
	    <p class="o_view_nocontent_smiling_face">
	      	Click to add a new directory.
	    </p>
	    <p>
			Directories can be used to structure and organize
			files directly in Odoo.
	    </p>
    </field>
</record>

<record id="action_dms_files_storage" model="ir.actions.act_window">
    <field name="name">Files</field>
    <field name="view_type">form</field>
	<field name="res_model">muk_dms.file</field>
	<field name="view_mode">kanban,tree,graph,pivot,form</field>
	<field name="domain">
		[
			("storage", "=",  active_id),
			("is_hidden", "=",  False),
		]
	</field>
	<field name="help" type="html">
	    <p class="o_view_nocontent_smiling_face">
	      	Click to add a new file.
	    </p>
	    <p>
			Files are used to save content directly in Odoo.
	    </p>
    </field>
</record>

<record id="action_dms_file_storage_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">
		[
			"&amp;", ("storage", "=",  active_id),
			"|",("active", "=",  False), ("active", "!=",  False)
		]
	</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_storage_search" model="ir.ui.view">
	<field name="name">muk_dms_storage.search</field>
	<field name="model">muk_dms.storage</field>
	<field name="arch" type="xml">
		<search>
			<field name="name" />
			<group expand="0" string="Group By">
				<filter string="Save Type" name="group_save_type" domain="[]" context="{'group_by':'save_type'}" />
			</group>
		</search>
	</field>
</record>

<record id="view_dms_storage_tree" model="ir.ui.view">
	<field name="name">muk_dms_storage.tree</field>
	<field name="model">muk_dms.storage</field>
	<field name="arch" type="xml">
		<tree string="Storages">
			<field name="name" />
			<field name="save_type" />
			<field name="is_hidden" />
			<field name="company" />
		</tree>
	</field>
</record>

<record id="view_dms_storage_form" model="ir.ui.view">
	<field name="name">muk_dms_storage.form</field>
	<field name="model">muk_dms.storage</field>
	<field name="arch" type="xml">
		<form string="Storage">
			<header>
				<button name="action_storage_migrate" type="object" string="Migrate Files" />
				<button  type="action" name="%(muk_dms.action_dms_file_storage_migration)d" 
					class="oe_stat_button" string="Manual File Migration" />
			</header>
			<sheet>
				<div class="oe_button_box" name="button_box">
					<button  type="action" name="%(muk_dms.action_dms_directories_storage)d" 
						class="oe_stat_button" icon="fa-folder-open-o" >
		                <field string="Directories" name="count_storage_directories" widget="statinfo"/>
	 				</button>    
	 				<button  type="action" name="%(muk_dms.action_dms_files_storage)d" 
	 					class="oe_stat_button" icon="fa-file-text-o" >
		                <field string="Files" name="count_storage_files" widget="statinfo"/>
	 				</button>     
                </div>
				<div class="oe_title">
					<label for="name" class="oe_edit_only" />
					<h1>
						<field name="name" />
					</h1>
				</div>
				<group name="save_storage">
					<group name="save_storage_left">
						<field name="save_type" />
					</group>
					<group name="save_storage_right">
					</group>
				</group>
				<group name="data_storage">
					<group>
						<field name="is_hidden" />
					</group>
					<group>
						<field name="company" />
					</group>
				</group>
				<notebook>
					<page name="page_roots" string="Root Directories">
						<field name="root_directories" groups="muk_dms.group_dms_manager"
							context="{'default_root_storage': active_id, 'default_is_root_directory': True}" >
							<tree string="Root Directories">
								<field name="name" />
								<field name="count_total_directories" />
								<field name="count_total_files" />
								<field name="size" widget="binary_size" />
							</tree>
						</field>
					</page>
				</notebook>
			</sheet>
		</form>
	</field>
</record>

<record id="action_dms_storage" model="ir.actions.act_window">
	<field name="name">Storages</field>
	<field name="res_model">muk_dms.storage</field>
	<field name="view_mode">tree,form</field>
	<field name="help" type="html">
	    <p class="o_view_nocontent_smiling_face">
	      	Create a new Storage object.
	    </p>
	    <p>
			Storages are used to configure your Documents. 
	    </p>
    </field>
</record>

<menuitem id="menu_dms_storage" name="Storages"
	parent="cat_menu_muk_dms_config_system" 
	action="action_dms_storage"
	sequence="5" />
	
<record id="view_dms_storage_new_form" model="ir.ui.view">
	<field name="name">muk_dms_storage.form</field>
	<field name="model">muk_dms.storage</field>
	<field name="inherit_id" ref="view_dms_storage_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_storage_step" />
	            <button special="cancel" string="Cancel" />
	        </footer>
	    </form>
    </field>
</record>

<record id="action_dms_storage_new" model="ir.actions.act_window">
	<field name="name">New Storage</field>
	<field name="res_model">muk_dms.storage</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_storage_new_form" />
</record>

</odoo>
