<?xml version="1.0"?>
<openerp>
    <data>
        <menuitem id="im_livechat" name="Live Chat" parent="mail.mail_feeds_main" groups="group_im_livechat"/>

        <record model="ir.actions.act_window" id="action_support_channels">
            <field name="name">Live Chat Channels</field>
            <field name="res_model">im_livechat.channel</field>
            <field name="view_mode">kanban,form</field>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to define a new live chat channel.
              </p><p>
                You can create channels for each website on which you want
                to integrate the live chat widget, allowing you website
                visitors to talk in real time with your operators.
              </p><p>
                Each channel has it's own URL that you can send by email to
                your customers in order to start chatting with you.
              </p>
            </field>
        </record>
        <menuitem name="Channels" parent="im_livechat" id="support_channels" action="action_support_channels" groups="group_im_livechat"/>


        <record model="ir.ui.view" id="support_channel_kanban">
            <field name="name">support_channel.kanban</field>
            <field name="model">im_livechat.channel</field>
            <field name="arch" type="xml">
                <kanban>
                    <field name="name"/>
                    <field name="web_page" widget="url"/>
                    <field name="are_you_inside"/>
                    <field name="user_ids"/>
                    <templates>
                        <t t-name="kanban-box">
                            <div class="oe_group_image">
                                <a type="open"><img t-att-src="kanban_image('im_livechat.channel', 'image_medium', record.id.value)" class="oe_group_photo"/></a>
                            </div>
                            <div class="oe_group_details">
                                <h4><a type="open"><field name="name"/></a></h4>
                                <div class="oe_kanban_footer_left">
                                    <span>
                                        <span class="oe_e">+</span> <t t-esc="(record.user_ids.raw_value || []).length"/>
                                    </span>
                                </div>
                                <div class="oe_group_button">
                                    <button t-if="record.are_you_inside.raw_value" name="quit" type="object" class="oe_group_join">Quit</button>
                                    <button t-if="! record.are_you_inside.raw_value" name="join" type="object">Join</button>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>


        <record id="support_channel_form" model="ir.ui.view">
            <field name="name">support_channel.form</field>
            <field name="model">im_livechat.channel</field>
            <field name="arch" type="xml">
                <form string="Support Channels" version="7.0">
                <sheet>
                    <field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/>
                    <div class="oe_title">
                        <label for="name" class="oe_edit_only"/>
                        <h1>
                            <field name="name" placeholder="e.g. YourWebsite.com"/>
                        </h1>
                        <div>
                            <button type="object" name="join" class="oe_highlight" string="Join Channel" attrs='{"invisible": [["are_you_inside", "=", True]]}'/>
                            <button type="object" name="quit" string="Leave Channel" attrs='{"invisible": [["are_you_inside", "=", False]]}'/>
                            <button type="object" name="test_channel" string="Test" attrs='{"invisible": [["web_page", "=", False]]}'/>
                            <field name="are_you_inside" invisible="1"/>
                        </div>
                    </div>

                    <group>
                        <group string="Operators">
                            <field name="user_ids" widget="many2many_kanban" nolabel="1" colspan="2">
                                <kanban>
                                    <field name="name"/>
                                    <templates>
                                        <t t-name="kanban-box">
                                            <div>
                                                <a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
                                                <div class="oe_group_details" style="min-height: 40px">
                                                    <img t-att-src="kanban_image('res.users', 'image', record.id.value)"
                                                        class="oe_avatar oe_kanban_avatar_smallbox" style="float:left; margin-right: 10px;"/>
                                                    <h4><field name="name"/></h4>
                                                </div>
                                            </div>
                                        </t>
                                    </templates>
                                </kanban>
                            </field>
                        </group>
                        <group string="Options">
                            <field name="button_text"/>
                            <field name="input_placeholder"/>
                            <field name="default_message" placeholder="e.g. Hello, how may I help you?"/>
                        </group>
                    </group>

                    <div attrs='{"invisible": [["web_page", "=", False]]}'>
                        <separator string="How to use the Live Chat widget?"/>
                        <p>
                            Copy and paste this code into your website, within the &amp;lt;head&amp;gt; tag:
                        </p>
                        <field name="script_external" readonly="1" class="oe_tag"/>
                        <p>
                            or copy this url and send it by email to your customers or suppliers:
                        </p>
                        <field name="web_page" readonly="1" class="oe_tag" widget="url"/>
                        <p>For website built with Odoo CMS, please install the website_livechat module. Then go to Settings > Website Settings and select the Live Chat Channel you want to add on your website.</p>
                    </div>

                </sheet>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_history">
            <field name="name">History</field>
            <field name="res_model">im_chat.message</field>
            <field name="view_mode">list</field>
            <field name="domain">[('to_id.channel_id', '!=', None)]</field>
            <field name="context">{'search_default_group_by_to_id': 1}</field>
        </record>
        <menuitem name="History" parent="im_livechat" id="history" action="action_history" groups="group_im_livechat_manager"/>

        <record id="im_message_form" model="ir.ui.view">
            <field name="name">im.chat.message.tree</field>
            <field name="model">im_chat.message</field>
            <field name="arch" type="xml">
                <tree string="History" create="false">
                    <field name="to_id"/>
                    <field name="create_date"/>
                    <field name="from_id"/>
                    <field name="message"/>
                </tree>
            </field>
        </record>

        <record id="im_message_search" model="ir.ui.view">
            <field name="name">im.chat.message.search</field>
            <field name="model">im_chat.message</field>
            <field name="arch" type="xml">
                <search string="Search history">
                    <filter name="to_id" string="My Sessions" domain="[('to_id.user_ids','in', uid)]"/>
                    <field name="from_id"/>
                    <field name="to_id"/>
                    <group expand="0" string="Group By...">
                        <filter name="group_by_to_id" string="Session" domain="[]" context="{'group_by':'to_id'}"/>
                        <filter name="group_by_date" string="Date" domain="[]" context="{'group_by':'create_date'}"/>
                    </group>
                </search>
            </field>
        </record>

    </data>
</openerp>
