<?xml version="1.0"?>
<openerp>
    <data>

        <menuitem id="base.menu_mail_gateway" name="Emails"
            parent="base.menu_base_config" sequence="1" />

        <record model="ir.ui.view" id="view_mailgate_message_form">
          <field name="name">mailgate.message.form</field>
            <field name="model">mailgate.message</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
             <form string="mailgate message">
                    <group colspan="4" col="6">
                        <field name="name" string="Subject" required="1" select="1"  widget="char" size="512"/>
                        <field name="date" required="1" select="1"/>
                        <field name="user_id" string="Owner" select="1"/>
                        <field name="partner_id" readonly="1" />
                    </group>
                    <notebook colspan="4">
                        <page string="Details">
                            <group col="2" colspan="2">
                                <separator string="Email Followers" colspan="4"/>
                                <field name="email_from" />
                                <field name="email_to" widget="char" size="512"/>
                                <field name="email_cc" widget="char" size="512"/>
                                <field name="email_bcc" widget="char" size="512" groups="base.group_extended"/>
                           </group>
                           <group col="2" colspan="2">
                                <separator string="Message Details" colspan="4"/>
                                <field name="model" readonly="1"/>
                                <group col="3" colspan="2">
                                    <field name="res_id"  readonly="1"/>
                                    <button name="open_document" string="Open Document" type="object" icon="gtk-jump-to"/>
                                </group>
                                <field name="message_id" />
                                <field name="ref_id" />
                           </group>
                           <separator string="Description" colspan="4"/>
                            <field name="description" nolabel="1" colspan="4" />
                        </page>
                        <page string="Attachments">
                            <separator string="Attachments" colspan="4"/>
                            <field name="attachment_ids" nolabel="1" colspan="4" readonly="1"/>
                        </page>
                    </notebook>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_mailgate_message_tree">
            <field name="name">mailgate.message.tree</field>
            <field name="model">mailgate.message</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Emails">
                    <field name="date" />
                    <field name="name" string="Subject"/>
                    <field name="email_from" string="From"/>
                    <field name="user_id" string="Owner"/>
                    <field name="message_id" string="Message" invisible="1"/>
                    <field name="partner_id" invisible="1"/>
                    <button name="open_document" string="Open Document" type="object" icon="gtk-jump-to"/>
                    <button name="open_attachment" string="Open Attachments" type="object" icon="gtk-jump-to"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="view_mailgate_message_search">
            <field name="name">mailgate.message.search</field>
            <field name="model">mailgate.message</field>
            <field name="type">search</field>
            <field name="arch" type="xml">
                <search string="Email Search">
                    <field name="name" string="Subject"/>
                    <field name="date" />
                    <field name="user_id" string="Owner"/>
                    <field name="partner_id" string="Partner Name"/>
                    <newline/>
                    <group expand="0" string="Group By..." groups="base.group_extended">
                        <filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
                        <filter string="Owner" name="User" icon="terp-personal" context="{'group_by':'user_id'}"/>
                        <separator orientation="vertical"/>
                         <filter string="Thread" icon="terp-mail-" domain="[]" context="{'group_by':'message_id'}"/>
                         <separator orientation="vertical"/>
                         <filter string="Month" help="Creation Month" icon="terp-go-month" domain="[]" context="{'group_by':'date'}"/>
                    </group>
                </search>
            </field>
        </record>




        <record id="action_view_mail_message" model="ir.actions.act_window">
            <field name="name">Messages</field>
            <field name="res_model">mailgate.message</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="search_view_id" ref="view_mailgate_message_search"/>
        </record>




        <record model="ir.ui.view" id="view_mailgate_thread_form">
            <field name="name">mailgate.thread.form</field>
            <field name="model">mailgate.thread</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Mailgateway Thread">
                    <separator string="History" colspan="4"/>
                    <field name="message_ids" nolabel="1" colspan="4" mode="tree,form">
                        <tree string="Mailgateway History">
                            <field name="display_text" />
                        </tree>
                        <form string="Mailgate History">
                            <field name="name" widget="char" size="512"/>
                            <field name="date" />
                            <field name="user_id" />
                            <field name="message_id" />
                            <field name="history" />
                            <notebook colspan="4">
                                <page string="Email Details">
                                    <group col="4" colspan="4">
                                        <separator string="Email Details" colspan="4"/>
                                        <field name="email_from" />
                                        <field name="email_to" widget="char" size="512"/>
                                        <field name="email_cc" widget="char" size="512"/>
                                        <field name="email_bcc" widget="char" size="512"/>
                                   </group>
                                </page>
                                <page string="Attachments">
                                    <separator string="Attachments" colspan="4"/>
                                    <field name="attachment_ids" nolabel="1" colspan="4" />
                                </page>
                            </notebook>
                        </form>
                    </field>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_mailgate_thread_tree">
            <field name="name">mailgate.thread.tree</field>
            <field name="model">mailgate.thread</field>
            <field name="type">tree</field>
            <field name="arch" type="xml">
                <tree string="Mailgateway Thread">
                    <field name="message_ids" />
                </tree>
            </field>
        </record>




         <!--        Emails action-->
        <record model="ir.actions.act_window" id="action_view_mailgate_thread">
            <field name="name">Mailgateway Threads</field>
            <field name="res_model">mailgate.thread</field>
            <field name="view_mode">tree,form</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="view_mailgate_thread_tree"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view1">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_mailgate_thread_tree"/>
            <field name="act_window_id" ref="action_view_mailgate_thread"/>
        </record>
        <record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view2">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_mailgate_thread_form"/>
            <field name="act_window_id" ref="action_view_mailgate_thread"/>
        </record>

        <!--        Emailsaction-->
        <record model="ir.actions.act_window" id="action_view_mailgate_message">
            <field name="name">Emails</field>
            <field name="res_model">mailgate.message</field>
            <field name="view_mode">tree,form</field>
            <field name="view_type">form</field>
            <field name="domain">[('history', '=', True)]</field>
            <field name="view_id" ref="view_mailgate_message_tree"/>
        </record>

        <record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view1">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_mailgate_thread_tree"/>
            <field name="act_window_id" ref="action_view_mailgate_thread"/>
        </record>
        <record model="ir.actions.act_window.view" id="action_view_mailgate_thread_view2">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_mailgate_thread_form"/>
            <field name="act_window_id" ref="action_view_mailgate_thread"/>
        </record>

        <act_window domain="[('partner_id', '=', active_id), ('history', '=', True)]"
            id="act_res_partner_emails" name="Emails"
            res_model="mailgate.message"
            src_model="res.partner"
            view_id="view_mailgate_message_tree"
            />

    <act_window
       id="act_res_partner_open_email" name="Attachments"
       res_model="ir.attachment"
       src_model="mailgate.message"
       domain="[('res_id', '=', res_id),('res_model','=',model)]"/>

           <menuitem id="base.menu_email_gateway_form"
               parent="base.menu_mail_gateway" action="action_view_mail_message" />

    </data>
</openerp>
