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

<record model="ir.ui.view" id="view_mail_mandrill_event_form">
    <field name="name">mail.mandrill.event.form</field>
    <field name="model">mail.mandrill.event</field>
    <field name="arch" type="xml">
        <form string="Mandrill email event">
            <sheet>
                <group>
                    <group>
                        <field name="message_id"/>
                        <field name="event_type"/>
                    </group>
                    <group>
                        <field name="timestamp"/>
                        <field name="time"/>
                        <field name="date"/>
                    </group>
                </group>
                <group attrs="{'invisible': [('event_type', 'not in', ('open', 'click'))]}">
                    <field name="url"/>
                </group>
                <group attrs="{'invisible': [('event_type', 'not in', ('open', 'click'))]}">
                    <group>
                        <field name="mobile"/>
                        <field name="ip"/>
                        <field name="user_country_id"/>
                    </group>
                    <group>
                        <field name="user_agent"/>
                        <field name="ua_family"/>
                        <field name="ua_type"/>
                        <field name="os_family"/>
                    </group>
                </group>
            </sheet>
        </form>
    </field>
</record>

<record model="ir.ui.view" id="view_mail_mandrill_event_tree">
    <field name="name">mail.mandrill.event.tree</field>
    <field name="model">mail.mandrill.event</field>
    <field name="arch" type="xml">
        <tree string="Mandrill email events" colors="grey:event_type in ('deferral');black:event_type in ('send');red:event_type in ('hard_bounce', 'soft_bounce', 'spam', 'reject');blue:event_type in ('unsub', 'click', 'open')">
            <field name="time"/>
            <field name="message_id" string="Message subject"/>
            <field name="event_type"/>
            <field name="date" invisible="1"/>
            <field name="ip"/>
            <field name="url"/>
            <field name="user_country_id" string="Country"/>
            <field name="os_family" string="OS"/>
            <field name="ua_family" string="User agent"/>
        </tree>
    </field>
</record>

<record model="ir.ui.view" id="view_mail_mandrill_event_search">
    <field name="name">mail.mandrill.event.search</field>
    <field name="model">mail.mandrill.event</field>
    <field name="arch" type="xml">
        <search string="Mandrill event Search">
            <field name="message_id" string="Message subject"
                   filter_domain="[('message_id','ilike',self)]"/>
            <field name="message_id" string="Subject"/>
            <field name="time" string="Time"/>
            <field name="date" string="Date"/>
            <field name="ip" string="IP"/>
            <field name="url" string="URL"/>
            <filter name="send" string="Send" domain="[('event_type', '=', 'send')]"/>
            <filter name="click" string="Click" domain="[('event_type', '=', 'click')]"/>
            <filter name="open" string="Open" domain="[('event_type', '=', 'open')]"/>
            <filter name="unsub" string="Unsubscribe" domain="[('event_type', '=', 'unsub')]"/>
            <filter name="bounce" string="Bounce"
                    domain="[('event_type', 'in', ('hard_bounce', 'soft_bounce'))]"/>
            <filter name="exception" string="Failed"
                    domain="[('event_type', 'in', ('reject', 'spam'))]"/>
            <separator/>
            <group expand="0" string="Group By">
                <filter string="Type" domain="[]" context="{'group_by': 'event_type'}"/>
                <filter string="Message subject" domain="[]" context="{'group_by': 'message_id'}"/>
                <filter string="OS" domain="[('os_family', '!=', False)]" context="{'group_by': 'os_family'}"/>
                <filter string="User agent" domain="[('ua_family', '!=', False)]" context="{'group_by': 'ua_family'}"/>
                <filter string="User agent type" domain="[('ua_type', '!=', False)]" context="{'group_by': 'ua_type'}"/>
                <filter string="Country" domain="[('user_country_id', '!=', False)]" context="{'group_by': 'user_country_id'}"/>
                <filter string="Month" domain="[]" context="{'group_by': 'date'}"/>
            </group>
        </search>
    </field>
</record>

<record id="action_view_mail_mandrill_event" model="ir.actions.act_window">
    <field name="name">Mandrill events</field>
    <field name="res_model">mail.mandrill.event</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="search_view_id" ref="view_mail_mandrill_event_search"/>
</record>

<!-- Add menu entry in Settings/Email -->
<menuitem name="Mandrill events" id="menu_mail_mandrill_event"
          parent="base.menu_email"
          action="action_view_mail_mandrill_event"/>

</data>
</openerp>