<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <!-- Email Template-->
        <record model="ir.ui.view" id="email_template_mailbox_form">
            <field name="name">email_template.mailbox.form</field>
            <field name="model">email_template.mailbox</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Emails">
                    <group col="4" colspan="4" name="headers">
                        <field name="email_from" select="1"/>
                        <field name="email_to" required="1" select="1" />
                        <field name="reply_to" select="2"/>
                        <field name="email_cc" select="1"/>
                        <field name="email_bcc" select="2"/>
                        <field name="date_mail" select="2"/>
                        <field name="subject" colspan="4" select="1"/>
                    </group>
                    <notebook colspan="4">
                        <page string="Standard Body">
                            <separator colspan="4" string="Standard Body" />
                            <notebook colspan="4">
                                <page string="Standard Body (Text)">
                                    <field name="body_text" nolabel="1" colspan="4" select="1"/>
                                </page>
                                <page string="Body (HTML-Web Client Only)">
                                    <field name="body_html" nolabel="1" colspan="4" />
                                </page>
                            </notebook>
                            <separator colspan="4" string="" />
                            <group col="4" colspan="4">
                                <field name="state" readonly="1" string="State"/>
                                <button name="send_this_mail" type="object" string="Send Mail" icon="terp-mail-message-new"/>
                            </group>
                        </page>

                        <page string="Attachments">
                            <separator colspan="4" string="Attachments" />
                            <field name="attachments_ids" colspan="4" nolabel="1" />
                        </page>
                        <page string="Advanced">
                            <field name="account_id" colspan="2" />
                            <field name="server_ref" colspan="2" />
                            <field name="mail_type" colspan="2" />
                            <field name="folder" colspan="2" select="2"/>
                            <field name="message_id" select="2"/>
                            <separator string="History" colspan="4" />
                            <field name="history" nolabel="1" colspan="4"/>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

        <!--============================================= TREE VIEWS =============================================-->
         <record id="view_email_template_mailbox_tree" model="ir.ui.view">
            <field name="name">email_template.mailbox.tree</field>
            <field name="model">email_template.mailbox</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Emails" colors="blue:folder=='drafts';grey:folder=='trash'">
                    <field name="subject" select="1" />
                    <field name="user" />
                    <field name="email_from" select="1" />
                    <field name="email_to"/>
                    <field name="date_mail" select="2" />
                    <field name="attachments_ids" select="2" />
                    <field name="folder" invisible="1"/>
                </tree>
            </field>
        </record>

        <record id="view_email_template_mailbox_search" model="ir.ui.view">
           <field name="name">email_template.mailbox.search</field>
           <field name="model">email_template.mailbox</field>
           <field name="type">search</field>
           <field name="arch" type="xml">
               <search string="Emails">
                    <filter icon="terp-document-new" string="Drafts" name="draft" domain="[('folder','=','drafts')]"/>
                    <filter icon="terp-mail-" string="Outbox" name="outbox" domain="[('folder','=','outbox')]"/>
                    <filter icon="terp-camera_test" string="Sent" domain="[('folder','=','sent')]"/>
                    <filter icon="terp-mail_delete" string="Trash" domain="[('folder','=','trash')]"/>
                    <separator orientation="vertical"/>
                    <filter icon="terp-personal+" string="Personal Emails" name="personal" domain="[('account_id.company','=','no')]"/>
                    <filter icon="terp-go-home" string="Company Emails" name="company" domain="[('account_id.company','=','yes')]"/>
                    <separator orientation="vertical"/>
                    <field name="subject"/>
                    <field name="email_from"/>
                    <field name="user">
                        <filter icon="terp-personal"
                            string="My Emails" help="My Emails" name="myemails"
                            domain="[('account_id.user','=', uid)]" />
                    </field>
                    <newline/>
                    <field name="email_to"/>
                    <field name="date_mail"/>
               </search>
           </field>
        </record>

        <record model="ir.actions.act_window" id="action_email_template_mailbox">
            <field name="name">Emails</field>
            <field name="res_model">email_template.mailbox</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="view_email_template_mailbox_tree" />
            <field name="context">{'group_by': [], 'search_default_outbox': 1}</field>
            <field name="search_view_id" ref="view_email_template_mailbox_search"/>
        </record>

        <!--======================================== MENUS ========================================-->

        <menuitem name="Emails"
            id="menu_email_template_personal_mails"
            parent="menu_email_template"
            action="action_email_template_mailbox" />

        <!-- Mailbox menu in Tools -->
        <menuitem name="Email Template" id="menu_email_template_tools"
            parent="base.menu_tools" />

        <menuitem name="Emails"
            id="menu_email_template_mails_tools"
            parent="menu_email_template_tools"
            action="action_email_template_mailbox" />

    </data>
</openerp>




