<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record model="ir.ui.view" id="view_utm_campaign_view_search">
        <field name="name">utm.campaign.view.search</field>
        <field name="model">utm.campaign</field>
        <field name="arch" type="xml">
            <search string="UTM Campaigns">
                <field name="title" string="Campaigns"/>
                <field name="tag_ids"/>
                <field name="user_id"/>
                <field name="is_auto_campaign"/>
                <filter string="My Campaigns" name="filter_assigned_to_me" domain="[('user_id', '=', uid)]"
                    help="Campaigns that are assigned to me"/>
                <separator/>
                <filter string="Archived" name="filter_inactive" domain="[('active', '=', False)]"/>
                <group expand="0" string="Group By">
                    <filter string="Stage" name="group_stage_id"
                        context="{'group_by': 'stage_id'}"/>
                    <filter string="Responsible" name="group_user_id"
                        context="{'group_by': 'user_id'}"/>
                    <filter string="Tags" name="group_tags_id"
                        context="{'group_by': 'tag_ids'}"/>
                </group>
            </search>
        </field>
    </record>

    <record model="ir.ui.view" id="utm_campaign_view_form">
        <field name="name">utm.campaign.view.form</field>
        <field name="model">utm.campaign</field>
        <field name="arch" type="xml">
            <form string="UTM Campaign">
                <header>
                    <field name="stage_id" widget="statusbar" options="{'clickable': '1'}"/>
                </header>
                <sheet>
                    <div class="oe_button_box d-flex justify-content-end" name="button_box">
                    </div>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                    <group id="top-group">
                        <field name="active" invisible="1"/>
                        <field class="text-break" name="title" string="Campaign Name" placeholder="e.g. Black Friday"/>
                        <field name="name" invisible="1"/>
                        <field name="user_id" widget="many2one_avatar_user" domain="[('share', '=', False)]"/>
                        <field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}"/>
                    </group>
                    <notebook>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="utm_campaign_view_tree">
        <field name="name">utm.campaign.view.tree</field>
        <field name="model">utm.campaign</field>
        <field name="arch" type="xml">
            <tree string="UTM Campaigns" multi_edit="1" sample="1">
                <field name="title" string="Name" readonly="1"/>
                <field name="name" column_invisible="True"/>
                <field name="user_id" widget="many2one_avatar_user"/>
                <field name="stage_id" decoration-bf="1"/>
                <field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
            </tree>
        </field>
    </record>

    <record id="utm_campaign_view_form_quick_create" model="ir.ui.view">
        <field name="name">utm.campaign.view.form.quick.create</field>
        <field name="model">utm.campaign</field>
        <field name="priority">1000</field>
        <field name="arch" type="xml">
            <form>
                <group>
                    <field name="name" invisible="1"/>
                    <field class="o_text_overflow" name="title" string="Campaign Name" placeholder="e.g. Black Friday"/>
                    <field name="user_id" widget="many2one_avatar_user" domain="[('share', '=', False)]"/>
                    <field name="tag_ids" widget="many2many_tags" class="o_field_highlight" options="{'color_field': 'color', 'no_create_edit': True}"/>
                </group>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="utm_campaign_view_kanban">
        <field name="name">utm.campaign.view.kanban</field>
        <field name="model">utm.campaign</field>
        <field name="arch" type="xml">
            <kanban default_group_by='stage_id' class="o_utm_kanban" on_create="quick_create" quick_create_view="utm.utm_campaign_view_form_quick_create" examples="utm_campaign" sample="1">
                <field name='color'/>
                <field name='user_id'/>
                <field name="stage_id"/>
                <field name='active'/>
                <templates>
                    <t t-name="kanban-menu">
                        <t t-if="widget.editable">
                            <a role="menuitem" type="edit" class="dropdown-item">Edit</a>
                        </t>
                        <t t-if="widget.deletable">
                            <a role="menuitem" type="delete" class="dropdown-item">Delete</a>
                        </t>
                        <a role="menuitem" class="dropdown-item o_kanban_mailing_active" name="toggle_active" type="object">
                            <t t-if="record.active.raw_value">Archive</t>
                            <t t-else="">Restore</t>
                        </a>
                        <div role="separator" class="dropdown-divider"/>
                        <ul class="oe_kanban_colorpicker" data-field="color"/>
                    </t>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
                            <div class="oe_kanban_content">
                                <div class="o_kanban_record_top">
                                    <div class="o_kanban_record_headings">
                                        <h3 class="oe_margin_bottom_8 o_kanban_record_title"><field name="title"/></h3>
                                    </div>
                                </div>
                                <div class="o_kanban_record_body">
                                    <field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
                                    <ul id="o_utm_actions" class="list-group list-group-horizontal my-0"/>
                                </div>
                                <div class="o_kanban_record_bottom h5 mt-2 mb-0">
                                    <div class="oe_kanban_bottom_left py-auto"/>
                                    <div class="oe_kanban_bottom_right">
                                         <field name="user_id" widget="many2one_avatar_user"/>
                                    </div>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <record id="utm_campaign_action" model="ir.actions.act_window">
        <field name="name">Campaigns</field>
        <field name="res_model">utm.campaign</field>
        <field name="view_mode">tree,kanban,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a campaign
            </p>
            <p>
                Campaigns are used to centralize your marketing efforts and track their results.
            </p>
        </field>
    </record>
</odoo>
