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

<!--
Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<odoo>
  <data>
    <!-- Forms -->
    <record id="golem_family_form" model="ir.ui.view">
      <field name="name">GOLEM Family Form</field>
      <field name="model">golem.family</field>
      <field name="arch" type="xml">
        <form>
          <sheet>
            <div colspan="2"
              style="background-color: #ccc; color: #fff; font-size: 150%; font-weight: bold; padding: 0.5%; text-align: center; margin-bottom: 1%;">Family form</div>
            <group>
              <div class="oe_title">
                <h1>
                  <label for="name" string="Family" class="oe_edit_only" />
                  <field name="name" class="oe_inline" placeholder="Name" />
                </h1>
              </div>
            </group>
            <group string="Address">
              <group>
                <field name="street" placeholder="Street..." />
                <field name="street2" />
                <field name="zip" placeholder="ZIP" />
                <field name="city" placeholder="City" />
              </group>
              <group>
                <field name="state_id" class="oe_no_button"
                  placeholder="State" />
                <field name="country_id" placeholder="Country"
                  class="oe_no_button" />
              </group>
            </group>
            <group string="Communication">
              <group>
                <field name="phone" placeholder="0000000000"
                  widget="phonefr" />
                <field name="mobile" placeholder="0000000000"
                  widget="phonefr" />
              </group>
              <group>
                <field name="email" widget="email"
                  placeholder="name@example.org" />
                <field name="website" widget="url"
                  placeholder="e.g. www.odoo.com"/>
              </group>
            </group>
            <notebook>
              <page string="Family members">
                <field name="member_ids" context="{'default_family_id': active_id}">
                  <tree delete="false">
                    <field name="name" />
                    <field name="family_role" />
                    <field name="phone" />
                    <field name="mobile" />
                    <field name="email" widget="email" />
                  </tree>
                </field>
              </page>
              <page string="Others">
                <group>
                  <field name="note" placeholder="Put an internal note..." />
                </group>
              </page>
            </notebook>
          </sheet>
          <div class="oe_chatter">
              <field name="message_follower_ids" widget="mail_followers" />
              <field name="message_ids" widget="mail_thread" />
          </div>
        </form>
      </field>
    </record>

    <!-- Kanban -->
    <record model="ir.ui.view" id="golem_family_kanban">
      <field name="name">GOLEM Family Kanban view</field>
      <field name="model">golem.family</field>
      <field name="arch" type="xml">
        <kanban>
          <field name="count" />
          <field name="name" />
          <field name="email" />
          <field name="phone" />
          <field name="mobile" />
          <field name="city" />
          <field name="country_id" />
          <field name="member_ids" />
          <templates>
            <t t-name="kanban-box">
              <div class="oe_kanban_vignette oe_semantic_html_override">
                <div class="oe_kanban_details">
                  <h4 class="oe_partner_heading">
                    <a type="open"><field name="name" /></a>
                  </h4>
                  <div class="oe_kanban_partner_links" />
                  <ul>
                    <li t-if="record.city.raw_value and !record.country_id.raw_value">
                      <field name="city" />
                    </li>
                    <li t-if="!record.city.raw_value and record.country_id.raw_value">
                      <field name="country_id" />
                    </li>
                    <li t-if="record.city.raw_value and record.country_id.raw_value">
                      <field name="city" />, <field name="country_id" />
                    </li>
                    <li t-if="record.phone.raw_value or record.mobile.raw_value">
                      <a t-attf-href="tel:#{record.phone.raw_value}">
                        <field name="phone" />
                      </a>
                      <a t-attf-href="tel:#{record.mobile.raw_value}">
                        <field name="mobile" />
                      </a>
                    </li>
                    <li t-if="record.email.raw_value">
                      <a t-attf-href="mailto:#{record.email.raw_value}">
                        <field name="email" />
                      </a>
                    </li>
                  </ul>
                  <field name="count" /> members <span t-if="record.count != 0"> :
                    <t t-foreach="record.member_ids.raw_value" t-as="member">
                      <t t-esc="member.name" />
                    </t>
                  </span>
                </div>
              </div>
            </t>
          </templates>
        </kanban>
      </field>
    </record>

    <!-- Trees -->
    <record id="golem_family_tree" model="ir.ui.view">
      <field name="name">Family list</field>
      <field name="model">golem.family</field>
      <field name="arch" type="xml">
        <tree>
          <field name="count" string="# Members" />
          <field name="name" />
          <field name="city" />
          <field name="email" />
          <field name="phone" />
        </tree>
      </field>
    </record>
    <record id="golem_family_role_tree" model="ir.ui.view">
      <field name="name">Family Role List</field>
      <field name="model">golem.family.role</field>
      <field name="arch" type="xml">
        <tree editable="top">
          <field name="name" />
        </tree>
      </field>
    </record>

    <!-- Searches -->
    <record id="golem_family_search" model="ir.ui.view">
      <field name="name">GOLEM Family Filters</field>
      <field name="model">golem.family</field>
      <field name="arch" type="xml">
        <search>
          <field name="name" />
          <field name="zip" />
          <field name="city" />
          <field name="phone" />
          <field name="mobile" />
          <field name="email" />
          <group string="Group By">
            <filter name="group_city" string="By city"
              context="{'group_by': 'city'}"/>
          </group>
        </search>
      </field>
    </record>

    <!-- Actions -->
    <act_window id="golem_family_action_list" name="GOLEM Family List"
      res_model="golem.family" view_mode="kanban,tree,form" />
    <act_window id="golem_family_role_action" name="GOLEM Family Role List"
      res_model="golem.family.role" view_mode="tree" />

    <!-- Menus -->
    <menuitem id="golem_family_menu" name="Families"
      sequence="17" groups="golem_base.group_golem_user"
      web_icon="golem_family,static/description/icon.png" />
    <menuitem id="golem_family_menu_list" name="Families"
      parent="golem_family_menu" action="golem_family_action_list" sequence="1"
      groups="golem_base.group_golem_user" />
    <menuitem id="golem_family_role_menu" name="Roles"
      parent="golem_family_menu" action="golem_family_role_action" sequence="5"
      groups="golem_base.group_golem_manager" />

  </data>
</odoo>