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

<!-- © 2014-2015 Grupo ESOC <www.grupoesoc.es>
     License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->

<openerp>
<data>

<record id="compose_form" model="ir.ui.view">
    <field name="name">Forward Email Form</field>
    <field name="model">mail_forward.compose_message</field>
    <field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
    <field name="arch" type="xml">
        <data>
            <!-- It's required to fill either `partner_ids` or
                 `destination_object_id` -->
            <xpath expr="//field[@name='partner_ids']" position="attributes">
                <attribute name="attrs">{
                    'required': [('destination_object_id', '=', False)]
                }</attribute>
            </xpath>

            <xpath expr="//label[@for='partner_ids']" position="before">
                <!-- Object where the message will be attached -->
                <field
                    attrs="{
                        'required': [('partner_ids', '=', [[6, False, []]])]}"
                    name="destination_object_id"/>

                <!-- If the message has attachments, should we move them to the
                     new object? -->
                <field
                    name="move_attachments"
                    attrs="{
                        'invisible': [
                            '|',
                            ('destination_object_id', '=', False),
                            ('attachment_ids', '=', [[6, False, []]])]}"/>
            </xpath>

            <!-- If there's no document to follow, hide the message -->
            <xpath expr="//span[text()='Followers of the document and']"
                   position="attributes">
                <attribute name="attrs">{
                    'invisible': [('destination_object_id', '=', False)]
                }</attribute>
            </xpath>
        </data>
    </field>
</record>

<record id="compose_action" model="ir.actions.act_window">
    <field name="name">Forward Email</field>
    <field name="res_model">mail_forward.compose_message</field>
    <field name="src_model">mail.message</field>
    <field name="type">ir.actions.act_window</field>
    <field name="view_id" ref="compose_form"/>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
    <field name="target">new</field>
</record>

</data>
</openerp>
