<?xml version="1.0" encoding="utf-8"?>
<!-- ********************************************************************** -->
<!-- See __openerp__.py file for Copyright and Licence Informations.         -->
<!-- ********************************************************************** -->
<openerp>
    <data>
        <!-- SHIFT.SHIFT VIEWS -->
        <record model="ir.ui.view" id="view_shift_form">
            <field name="name">shift.shift.form</field>
            <field name="model">shift.shift</field>
            <field name="arch" type="xml">
                <form string="Shifts" create="false">
                    <header>
                        <button string="Confirm Shift" name="button_confirm" states="draft" type="object" class="oe_highlight" groups="base.group_user"/>
                        <button string="Finish Shift" name="button_done" states="confirm" type="object" class="oe_highlight" groups="base.group_user"/>
                        <button string="Set To Draft" name="button_draft" states="cancel,done" type="object" groups="base.group_user"/>
                        <button string="Cancel Shift" name="button_cancel" states="draft,confirm" type="object" groups="coop_shift.group_shift_cancel_shifts"/>
                        <field name="state" widget="statusbar" statusbar_visible="draft,confirm,done"/>
                    </header>
                    <sheet>
                        <div class="oe_button_box" name="button_box" groups="base.group_user">
                            <button name="toggle_active" type="object"
                                    class="oe_stat_button" icon="fa-archive" attrs="{'invisible': [('state', 'not in', ['done', 'cancel'])]}">
                                <field name="active" widget="boolean_button"
                                    options='{"terminology": "archive"}'/>
                            </button>
                            <button name="%(coop_shift.act_shift_registration_from_shift)d"
                                type="action"
                                class="oe_stat_button oe_event_attendee_button"
                                icon="fa-users"
                                help="Register with this shift"
                                context="{'is_standard_ticket': True}">
                                <field name="seats_expected" widget="statinfo" string="Attendees"/>
                            </button>
                        </div>
                        <div class="oe_title">
                            <label for="name" class="oe_edit_only"/>
                            <h1><field name="name" placeholder="Shift Name"/></h1>
                        </div>
                        <group name="main_field_group">
                            <group>
                                <field name="shift_template_id" groups="coop_shift.group_shift_manager" options="{'no_create': True}"/>
                                <field name="user_ids" options="{'no_create': True}" widget="many2many_tags"/>
                                <field name="shift_type_id" options="{'no_create': True}"/>
                                <!-- <field name="date_tz" /> -->
                            </group>
                            <group name="datetime">
                                <field name="week_number"/>
                                <field name="date_begin" string="Start"/>
                                <field name="date_end" string="End"/>
                            </group>
                            <group groups="base.group_no_one">
                                <!-- <field name="organizer_id"/> -->
                                <field name="company_id" groups="base.group_multi_company"/>
                            </group>
                        </group>
                        <notebook>
                            <page name="registrations" string="Registrations">
                                <group>
                                    <group>
                                        <field name="auto_confirm" invisible="1"/>
                                        <field name="seats_min"/>
                                        <field name="seats_availability" widget='radio'/>
                                        <field name="seats_max" attrs="{'invisible': [('seats_availability', '=', 'unlimited')], 'required': [('seats_availability', '=', 'limited')]}"/>
                                    </group>
                                </group>
                                <field name="shift_ticket_ids" context="{'default_name': name}">
                                    <tree string="Tickets" editable="bottom">
                                        <field name="name"/>
                                        <field name="product_id" context="{'shift_ok':1}" domain="[('shift_type_id','!=',False)]" options="{'no_create': True}"/>
                                        <field name="seats_max"/>
                                        <field name="seats_reserved" readonly="1"/>
                                        <field name="seats_available" readonly="1"/>
                                    </tree>
                                </field>
                            </page>
                            <page string="Email Schedule" groups="event.group_email_scheduling">
                                <group>
                                    <field name="reply_to"/>
                                </group>
                                <field name="shift_mail_ids">
                                    <tree string="Email Schedule" editable="bottom">
                                        <field name="sequence" widget="handle"/>
                                        <field name="template_id"/>
                                        <field name="interval_nbr" attrs="{'readonly':[('interval_unit','=','now')]}"/>
                                        <field name="interval_unit"/>
                                        <field name="interval_type"/>
                                        <field name="done"/>
                                    </tree>
                                </field>
                            </page>
                        </notebook>
                    </sheet>
                    <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
                        <field name="message_ids" widget="mail_thread"/>
                    </div>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="view_shift_tree">
            <field name="name">shift.shift.tree</field>
            <field name="model">shift.shift</field>
            <field name="arch" type="xml">
                <tree string="Shifts" decoration-bf="message_needaction==True" decoration-danger="(seats_min and seats_min&gt;seats_reserved) or (seats_max and seats_max&lt;seats_reserved)" decoration-muted="state=='cancel'" create="false">
                    <field name="name"/>
                    <field name="week_number"/>
                    <field name="shift_type_id"/>
                    <field name="date_begin"/>
                    <field name="date_end"/>
                    <field name="seats_reserved"/>
                    <field name="seats_min"/>
                    <field name="seats_max" invisible="1"/>
                    <field name="user_ids"/>
                    <field name="state"/>
                    <field name="message_needaction" invisible="1"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="view_shift_kanban">
            <field name="name">shift.shift.kanban</field>
            <field name="model">shift.shift</field>
            <field name="arch" type="xml">
                <kanban class="o_event_kanban_view" create="false">
                    <field name="user_ids"/>
                    <field name="date_begin"/>
                    <field name="date_end"/>
                    <field name="seats_unconfirmed"/>
                    <field name="seats_reserved"/>
                    <field name="seats_used"/>
                    <field name="seats_available"/>
                    <field name="color"/>
                    <field name="state" invisible="1"/>
                    <templates>
                        <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="o_dropdown_kanban dropdown">

                                    <a class="dropdown-toggle btn" data-toggle="dropdown" href="#" >
                                        <span class="fa fa-bars fa-lg"/>
                                    </a>
                                    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                                        <t t-if="widget.deletable">
                                            <li><a type="delete">Delete</a></li>
                                        </t>
                                        <li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
                                    </ul>
                                </div>
                                <div class="o_event_left">
                                    <h4><field name="name"/></h4>
                                </div>
                                <div class="o_event_right">
                                    <div>
                                        <i class="fa fa-clock-o"/>
                                        <b>From</b> <t t-esc="moment(record.date_begin.raw_value).format('lll')"/>
                                    </div>
                                    <div>
                                        <i class="fa fa-clock-o"/>
                                        <b>To</b> <t t-esc="moment(record.date_end.raw_value).format('lll')"/>
                                    </div>
                                    <h4>
                                        <a name="%(act_shift_registration_from_shift)d" type="action">
                                            <t t-esc="record.seats_reserved.raw_value"> Expected attendees </t>
                                        </a>
                                        <br/>
                                             <t t-esc="record.seats_available.raw_value"/> Available Seats
                                        <!-- <a name="action_shift_registration_report" type="object" >&#40;stats&#41;</a> -->
                                    </h4>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record model="ir.ui.view" id="view_shift_calendar">
            <field name="name">shift.shift.calendar</field>
            <field name="model">shift.shift</field>
            <field eval="2" name="priority"/>
            <field name="arch" type="xml">
                <calendar color="shift_type_id" date_start="date_begin" date_stop="date_end" string="Shift Organization">
                    <field name="name"/>
                    <field name="shift_type_id"/>
                </calendar>
            </field>
        </record>

        <record model="ir.ui.view" id="view_shift_search">
            <field name="name">shift.shift.search</field>
            <field name="model">shift.shift</field>
            <field name="arch" type="xml">
                <search string="Shifts">
                    <field name="name" filter_domain="['|', ('name','ilike',self), ('begin_date_string','ilike',self')]" string="Shifts"/>
                    <filter string="Unread Messages" name="message_needaction" domain="[('message_needaction','=',True)]"/>
                    <separator/>
                    <filter string="Unconfirmed" name="draft" domain="[('state','=','draft')]" help="Shifts in New state"/>
                    <filter string="Confirmed" name="confirmed" domain="[('state','=','confirm')]" help="Confirmed shifts"/>
                    <filter string="Finished" name="finished" domain="[('state','=','done')]" help="Finished shifts"/>
                    <separator/>
                    <filter string="My Shifts" help="My Shifts" domain="[('user_ids','in',uid)]"/>
                    <separator/>
                    <filter string="Upcoming" name="upcoming"
                        domain="['&amp;', ('state', '!=', 'cancel'), ('date_begin','&gt;=', datetime.datetime.combine(context_today(), datetime.time(0,0,0)))]" help="Upcoming shifts from today" />
                    <field name="week_number"/>
                    <field name="week_list"/>
                    <field name="shift_type_id"/>
                    <field name="user_ids"/>
                    <field name="begin_date_string" string="Date"/>
                    <separator/>
                    <filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
                    <group expand="0" string="Group By">
                        <filter string="Shift Type" context="{'group_by':'shift_type_id'}"/>
                        <filter string="Week" context="{'group_by':'week_number'}"/>
                        <filter string="Status" context="{'group_by':'state'}"/>
                        <filter string="Start Month" domain="[]" context="{'group_by':'date_begin'}"/>
                    </group>
                </search>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_shift_view">
           <field name="name">Shift</field>
           <field name="type">ir.actions.act_window</field>
           <field name="res_model">shift.shift</field>
           <field name="view_type">form</field>
           <field name="view_mode">kanban,tree,form</field>
           <field name="context">{"search_default_confirmed":1}</field>
           <field name="search_view_id" ref="view_shift_search"/>
           <field name="help" type="html"><p class="oe_view_nocontent_create">
    Click to add a new shift.
</p><p>
    Odoo helps you schedule and efficiently organize your shifts:
    track subscriptions and participations, automate the confirmation emails,
    sell tickets, etc.
</p></field>
        </record>

        <menuitem
            name="Shifts"
            id="menu_shift_shift"
            action="action_shift_view"
            parent="coop_shift.shift_menu"
            sequence="10"/>
    </data>
</openerp>