<?xml version="1.0" encoding="utf-8" ?>
<odoo>
  <record id="view_eurooffice_form" model="ir.ui.view">
    <field name="name">eurooffice.odoo.templates.form</field>
    <field name="model">eurooffice.odoo.templates</field>
    <field name="arch" type="xml">
      <form string="Create template">
        <sheet>
          <group string="Template creation">
            <div class="text-muted" colspan="2"> Use this form to create a new fillable PDF template
              for your Odoo modules. Start by entering a <span class="fw-bolder">name </span> for
              your template to easily identify it later in the Euro-Office Templates list. </div>
            <div class="text-muted" colspan="2"> Choose the <span class="fw-bolder">Odoo module </span>
              (e.g., Employee, Invoice, Sales Order) that the template will be linked to. The chosen
              model defines the data fields available for automatic form filling. </div>
            <field name="name" required="1" />
            <field
              name="template_model_id"
              options="{'no_create': True, 'no_create_edit':True, 'no_open':True}"
              help="Model for which the template is being created."
              required="1"
            />
            <field name="template_model_related_name" invisible="1" />
            <field name="template_model_model" invisible="1" />
            <field name="hide_file_field" invisible="1" />
          </group>
          <group string="Template uploading" attrs="{'invisible': [('hide_file_field', '=', True)]}">
            <div class="text-muted" colspan="2"> If you already have a <span class="fw-bolder">prepared
              PDF file</span> with fillable fields, you can upload it here </div>
            <field
              name="file"
              options="{'accepted_file_extensions': '.pdf', 'attachment': False}"
              help="Select an existing template. Leave the field blank to create a blank template."
            />
          </group>
          <group>
            <div colspan="2">
              <div class="text-muted">
                Once you've saved the template, return to the Euro-Office Templates list.
              </div>
              <div class="text-muted">
                Locate your newly created template and set up the connections between the form
                fields in the Euro-Office editor and the corresponding data fields from the selected
                Odoo model.
              </div>
            </div>
          </group>
        </sheet>
      </form>
    </field>
  </record>

  <record id="view_eurooffice_kanban_search" model="ir.ui.view">
    <field name="name">eurooffice.odoo.templates.kanban.search</field>
    <field name="model">eurooffice.odoo.templates</field>
    <field name="arch" type="xml">
      <search>
        <field name="name" />
        <field name="template_model_name" />
        <group expand="0" string="Group By">
          <filter string="Model" name="template_model_id" context="{'group_by': 'template_model_id'}" />
        </group>
        <searchpanel>
          <field name="template_model_id" string="Model" enable_counters="1" />
        </searchpanel>
      </search>
    </field>
  </record>

  <record id="view_eurooffice_kanban" model="ir.ui.view">
    <field name="name">eurooffice.odoo.templates.kanban</field>
    <field name="model">eurooffice.odoo.templates</field>
    <field name="arch" type="xml">
      <kanban js_class="eurooffice_kanban">
        <field name="id" />
        <field name="attachment_id" />
        <field name="mimetype" />
        <field name="create_uid" />
        <field name="create_date" />
        <field name="name" />
        <field name="template_model_name" />
        <field name="template_model_related_name" />
        <field name="template_model_model" />
        <templates>
          <t t-name="kanban-box">
            <div class="oe_kanban_global_area o_kanban_attachment oe_kanban_global_click">
              <div class="o_kanban_image">
                <div class="o_kanban_image_wrapper">
                  <div class="o_image o_image_thumbnail" t-att-data-mimetype="record.mimetype.value" />
                </div>
              </div>
              <div class="o_kanban_details">
                <div class="o_kanban_details_wrapper">
                  <div class="o_kanban_record_title">
                    <field name="name" class="o_text_overflow" />
                  </div>
                  <div class="o_kanban_record_body">
                    <t t-if="template_model_related_name">
                      <field name="template_model_related_name" widget="badge" />
                    </t>
                    <t t-else="">
                      <field name="template_model_name" widget="badge" />
                    </t>
                  </div>
                  <div class="o_kanban_record_bottom">
                    <span class="oe_kanban_bottom_left">
                      <field name="create_date" widget="date" />
                    </span>
                    <div class="oe_kanban_bottom_right oe_eurooffice_kanban_bottom_right">
                      <field name="create_uid" widget="many2one_avatar_user" />
                    </div>
                  </div>
                  <div class="o_dropdown_kanban dropdown" tabindex="-1">
                    <a
                      class="dropdown-toggle o-no-caret btn"
                      data-bs-toggle="dropdown"
                      href="#"
                      role="button"
                      aria-label="Dropdown menu"
                      title="Dropdown menu"
                    >
                      <span class="fa fa-ellipsis-v" />
                    </a>
                    <div class="dropdown-menu" role="menu" aria-labelledby="dLabel">
                      <a t-if="widget.editable" type="edit" class="dropdown-item">Edit</a>
                      <a t-if="widget.deletable" type="delete" class="dropdown-item">Delete</a>
                      <a
                        t-attf-href="/web/content/ir.attachment/#{record.attachment_id.raw_value}/datas?download=true"
                        download=""
                        class="dropdown-item"
                      >Download</a>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </t>
        </templates>
      </kanban>
    </field>
  </record>

  <record model="ir.actions.act_window" id="action_eurooffice_odoo_templates">
    <field name="name">Euro-Office Templates</field>
    <field name="res_model">eurooffice.odoo.templates</field>
    <field name="view_mode">kanban,form</field>
  </record>

  <menuitem
    id="eurooffice_menu"
    name="Euro-Office Templates"
    web_icon="eurooffice_odoo_templates,static/description/icon.svg"
    sequence="30"
    groups="eurooffice_odoo_templates.group_eurooffice_odoo_templates_user,eurooffice_odoo_templates.group_eurooffice_odoo_templates_admin"
    action="action_eurooffice_odoo_templates"
  />
</odoo>
