<?xml version="1.0" encoding="UTF-8"?>
<odoo>
        <record model="ir.ui.view" id="kanban_view_faculty">
            <field name="name">Faculty Kanban</field>
            <field name="model">op.faculty</field>
            <field name="arch" type="xml">
                <kanban sample="1">
                    <field name="id"/>
                    <field name="image_1920"/>
                    <templates>
                        <t t-name="card" class="flex-row">
                            <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                            <aside class="o_kanban_aside_full">
                                <t t-if="record.image_1920.value">
                                    <div class="o_kanban_image_fill position-relative w-100">
                                        <field name="image_1920" alt="Contact image" class="h-100" widget="image" options="{'img_class': 'object-fit-cover'}"/>
                                    </div>
                                </t>
                                <t t-else="">
                                    <div class="o_kanban_image_fill position-relative w-100">
                                        <field name="avatar_128" class="h-100" widget="image" options="{'img_class': 'object-fit-cover'}"/>
                                    </div>
                                </t>
                            </aside>
                            <main class="ml16 ps-2 ps-md-0">
                                <div class="mb-1">
                                    <field name="name" class="mb-0 fw-bold fs-5"/>
                                </div>
                                <div class="text-truncate">
                                    <i class="fa fa-fw me-2 fa-envelope text-primary" title="Email" t-if="record.email"/>
                                    <field name="email" class="text-truncate"/>
                                </div>
                                <div class="text-truncate">
                                    <i class="fa fa-fw me-2 fa-phone text-primary" title="phone" t-if="record.phone"/>
                                    <field name="phone" class="text-truncate"/>
                                </div>
                                <footer class="py-0">
                                    <div class="d-flex ms-auto">
                                        <field name="activity_ids" widget="kanban_activity" class="m-2 ms-2"/>
                                    </div>
                                </footer>
                            </main>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="view_op_faculty_tree" model="ir.ui.view">
            <field name="name">op.faculty.list</field>
            <field name="model">op.faculty</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <list string="Faculty">
                    <field name="title"/>
                    <field name="name"/>
                    <field name="gender" optional="show"/>
                    <field name="phone" optional="show"/>
                    <field name="email" optional="show"/>
                    <field name="blood_group"/>
                    <field name="emergency_contact" optional="hide"/>
                    <field name="main_department_id" groups="openeducat_core.group_multi_department"/>
                    <field name="allowed_department_ids" widget="many2many_tags"
                           groups="openeducat_core.group_multi_department"/>
                </list>
            </field>
        </record>

        <record id="view_op_faculty_form" model="ir.ui.view">
            <field name="name">op.faculty.form</field>
            <field name="model">op.faculty</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <form string="Faculty" js_class="hr_employee_form">
                    <header groups="openeducat_core.group_op_back_office_admin">
                    </header>
                    <sheet>
                        <div name="button_box" class="oe_button_box">
                        </div>

                        <field name="active" invisible="True"/>
                        <widget name="web_ribbon" title="Archived" bg_color="bg-danger"
                                invisible = "active == True"/>
                        <div class="row flex-column flex-sm-row align-items-center">
                            <div class="o_employee_avatar ms-2 p-0 h-100 mw-25 align-self-start align-self-sm-center">
                                <field name="image_1920" widget='image' class="m-0" options='{"size": [128,158], "zoom": true, "preview_image":"avatar_128"}'/>
                            </div>
                            <div class="align-self-start o_employee_form_header_info">
                                <div class="oe_title ps-0 pe-2 mw-100">
                                    <h5 class="d-flex align-items-baseline mb-0">
                                        <field name="title" options="{'no_create': True}" placeholder="Title"/>
                                    </h5>
                                    <div class="d-flex faculty-name">
                                        <div class="">
                                            <h1 class="d-md-flex align-items-center gap-1 w-50">
                                                <field name="name" placeholder="Name" required="True" invisible="True"/>
                                                <field name="first_name" widget="inline_char" required="1" placeholder="First Name"/>
                                                <field name="middle_name" widget="inline_char" placeholder="Middle Name"/>
                                                <field name="last_name" widget="inline_char" placeholder="Last Name"/>
                                            </h1>
                                        </div>
                                    </div>
                                    <div class="d-flex align-items-baseline w-md-50">
                                        <i class="fa fa-fw me-1 fa-envelope text-primary" title="Email"/>
                                        <field name="email" class="w-100" widget="email" placeholder="Email"/>
                                    </div>
                                    <div class="d-flex align-items-baseline w-md-50">
                                        <i class="fa fa-fw me-1 fa-phone text-primary" title="Phone"/>
                                        <field name="phone" class="w-100" widget="phone" placeholder="Phone"/>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <br/>
                        <group>
                            <group>
                                <field name="gender"/>
                                <field name="birth_date"/>
                                <label for="street" string="Address"/>
                                <div name="o_address_format">
                                    <field name="street" placeholder="Street..."/>
                                    <field name="street2" placeholder="Street2"/>
                                    <div class="address_format d-md-flex">
                                        <field name="city" placeholder="City" />
                                        <field name="state_id" class="oe_no_button" placeholder="State"
                                                 options="{&quot;no_open&quot;: True}"/>
                                        <field name="zip" placeholder="ZIP" />
                                    </div>
                                    <field name="country_id" placeholder="Country" class="oe_no_button"
                                            options="{&quot;no_open&quot;: True}"/>
                                </div>
                                <field name="emergency_contact" context="{'show_address': 1}"
                                        options="{&quot;always_reload&quot;: True}"/>
                            </group>
                            <group>
                                <field name="nationality"/>
                                <field name="lang"/>
                                <field name="emp_id"/>
                                <field name="main_department_id"
                                        groups="openeducat_core.group_multi_department"/>
                                <field name="blood_group"/>
                                <field name="user_id" string="User" readonly="1"/>
                                <field name="partner_id" placeholder="Partner" required="0"/>
                                <field name="allowed_department_ids" widget="many2many_tags"
                                        groups="openeducat_core.group_multi_department"/>
                            </group>
                        </group>
                        <notebook colspan="4">
                            <page name="other_information" string="Other Information">
                                <group name="other_info">
                                    <field name="child_ids" mode="kanban" context="{'default_parent_id': id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_lang': lang, 'default_user_id': user_id, 'default_type': is_company and 'contact' or 'other'}">
                                        <kanban color="color">
                                            <field name="color"/>
                                            <field name="type"/>
                                            <field name="is_company"/>
                                            <templates>
                                                <t t-name="card" class="flex-row">
                                                    <aside class="o_kanban_aside_full">
                                                        <field name="avatar_128" class="o_kanban_image_fill w-100" widget="image" options="{'img_class': 'object-fit-cover'}" alt="Contact image" invisible="type != 'contact'"/>
                                                        <field name="avatar_128" class="o_kanban_image_fill w-100" widget="image" options="{'img_class': 'object-fit-contain p-2'}" alt="Contact image" invisible="type == 'contact'"/>
                                                    </aside>
                                                    <main class="ps-2 ps-md-0">
                                                        <field name="name" invisible="not name" class="fw-bold"/>
                                                        <field name="type" invisible="name" class="fw-bold"/>
                                                        <div t-if="record.email.raw_value" class="text-truncate">
                                                            <i class="fa fa-fw me-1 fa-envelope text-primary" title="Email"/>
                                                            <field name="email"/>
                                                        </div>
                                                        <div t-if="record.phone.raw_value">
                                                            <i class="fa fa-fw me-1 fa-phone text-primary" title="Phone"/>
                                                            <field name="phone"/>
                                                        </div>
                                                        <div invisible="not function or is_company">
                                                            <i class="fa fa-fw me-1 fa-suitcase text-primary" title="Position"/>
                                                            <field name="function"/>
                                                        </div>
                                                        <div t-if="record.type.raw_value != 'contact' and (record.city.raw_value or record.country_id.raw_value)">
                                                            <i class="fa fa-fw me-1 fa-map-marker text-primary" title="Location"/>
                                                            <field name="city"/>
                                                            <span t-if="record.city.raw_value and record.country_id.raw_value">, </span>
                                                            <field name="country_id"/>
                                                        </div>
                                                    </main>
                                                </t>
                                            </templates>
                                        </kanban>
                                        <form string="Contact / Address">
                                            <sheet>
                                                <field name="type" required="1" widget="radio" options="{'horizontal': true}"/>
                                                <div class="d-flex align-items-center gap-3">
                                                    <field name="image_1920" widget="contact_image" nolabel="1" options="{'preview_image': 'avatar_128', 'size': [100,100], 'img_class': 'rounded border'}"/>
                                                    <div class="flex-grow-1">
                                                        <h3>
                                                            <field name="name" class="d-block" string="Name" default_focus="1" required="type == 'contact'" placeholder="e.g. Brandon Freeman"/>
                                                        </h3>
                                                        <div class="row flex-row">
                                                            <div class="d-flex align-items-baseline">
                                                                <i class="fa fa-fw me-1 fa-envelope text-primary" title="Email"/>
                                                                <field name="email" widget="email" class="w-100" context="{'gravatar_image': True}" required="user_ids" placeholder="Email"/>
                                                            </div>
                                                            <div class="d-flex align-items-baseline">
                                                                <i class="fa fa-fw me-1 fa-phone text-primary" title="Phone"/>
                                                                <field name="phone" widget="phone" class="w-100" placeholder="Phone"/>
                                                            </div>
                                                            <div invisible="is_company or type != 'contact'" class="d-flex align-items-baseline">
                                                                <i class="fa fa-fw me-1 fa-suitcase text-primary" title="Position"/>
                                                                <field name="function" placeholder="Job title"/>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <group invisible="type == 'contact'" name="other_info">
                                                    <group>
                                                        <span class="o_form_label o_td_label o_address_type">
                                                            <field name="type_address_label" readonly="1" class="fw-bold"/>
                                                        </span>
                                                        <div class="o_address_format" name="div_address">
                                                            <field name="street" placeholder="Street..." class="o_address_street"/>
                                                            <field name="street2" placeholder="Street 2..." class="o_address_street"/>
                                                            <field name="city" placeholder="City" class="o_address_city"/>
                                                            <field name="state_id" class="o_address_state" placeholder="State" options="{'no_open': True, 'no_quick_create': True}" context="{'country_id': country_id, 'default_country_id': country_id, 'zip': zip}"/>
                                                            <field name="zip" placeholder="ZIP" class="o_address_zip"/>
                                                            <field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
                                                        </div>
                                                    </group>
                                                </group>
                                                <group>
                                                    <field name="company_id" invisible="1"/>    <!-- Need to save value from parented record, cf onchange -->
                                                    <label for="comment"/>
                                                    <field name="comment" options="{'height': 100}" placeholder="Internal notes..." nolabel="1"/>
                                                </group>
                                                <field name="lang" invisible="True"/>  <!-- Need to add lang to save default value from parented record -->
                                            </sheet>
                                        </form>
                                    </field>
                                </group>
                            </page>
                            <page name="subjects" string="Subjects">
                                <field name="faculty_subject_ids" colspan="4" nolabel="1"/>
                            </page>
                        </notebook>
                    </sheet>
                    <chatter/>
                </form>
            </field>
        </record>

        <record id="view_op_faculty_search" model="ir.ui.view">
            <field name="name">op.faculty.search</field>
            <field name="model">op.faculty</field>
            <field name="priority" eval="8"/>
            <field name="arch" type="xml">
                <search string="Faculty">
                    <field name="name"/>
                    <field name="blood_group"/>
                    <field name="main_department_id"/>
                    <field name="allowed_department_ids"/>
                    <newline/>
                    <group>
                        <filter name="blood_group" string="Blood Group" domain="[]"
                                context="{'group_by':'blood_group'}"/>
                        <filter name="nationality" string="Nationality" domain="[]"
                                context="{'group_by':'nationality'}"/>
                        <filter name="language" string="Language" domain="[]" context="{'group_by':'lang'}"/>
                        <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
                    </group>
                </search>
            </field>
        </record>

        <record id="faculty_view_activity" model="ir.ui.view">
            <field name="name">op.faculty.activity</field>
            <field name="model">op.faculty</field>
            <field name="arch" type="xml">
                <activity string="Contacts">
                    <field name="id"/>
                    <templates>
                        <div t-name="activity-box">
                            <img t-att-src="activity_image('op.faculty', 'image_1920', record.id.raw_value)" role="img" t-att-title="record.name.value" t-att-alt="record.name.value"/>
                            <div class="ms-2">
                                <field name="name" display="full" class="o_text_block"/>
                            </div>
                        </div>
                    </templates>
                </activity>
            </field>
        </record>

        <record model="ir.actions.act_window" id="act_open_op_faculty_view">
            <field name="name">Faculties</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">op.faculty</field>
            <field name="path">faculty</field>
            <field name="binding_view_types">form</field>
            <field name="view_mode">kanban,list,form,activity</field>
            <field name="search_view_id" ref="view_op_faculty_search"/>
            <field name="domain">[]</field>
            <field name="context">{}</field>
        </record>

        <record model="ir.actions.act_window.view" id="act_open_op_faculty_view_form">
            <field name="act_window_id" ref="act_open_op_faculty_view"/>
            <field name="sequence" eval="20"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_op_faculty_form"/>
        </record>

        <record model="ir.actions.act_window.view" id="act_open_op_faculty_view_tree">
            <field name="act_window_id" ref="act_open_op_faculty_view"/>
            <field name="sequence" eval="10"/>
            <field name="view_mode">list</field>
            <field name="view_id" ref="view_op_faculty_tree"/>
        </record>

        <record model="ir.actions.act_window.view" id="act_open_op_faculty_view_kanban">
            <field name="act_window_id" ref="act_open_op_faculty_view"/>
            <field name="sequence" eval="5"/>
            <field name="view_mode">kanban</field>
            <field name="view_id" ref="kanban_view_faculty"/>
        </record>

        <record model="ir.actions.act_window" id="act_open_op_faculty_view_2">
            <field name="name">Faculties</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">op.faculty</field>
            <field name="path">faculties</field>
            <field name="binding_view_types">form</field>
            <field name="view_mode">kanban,list,form</field>
            <field name="search_view_id" ref="view_op_faculty_search"/>
            <field name="domain">[]</field>
            <field name="context">{}</field>
        </record>

</odoo>
