Comment 3 for bug 1156830

Revision history for this message
Daniel Hammerschmidt (redneck) wrote :

Hello Amit,

thank you for you comment.

I know, it is not a bug and the wishlist is what I have expected.

Currently I am "playing around" with partners, crm and the new great web-client. I wanted to have different avatars for non-company-partners of type 'contact' and other non-company-partners (a human head next to a delivery address looks somehow wrong) in the kanaban-view.

Following the whole thing:
[code]
<record id="view_partner_kanban" model="ir.ui.view">
  <field name="inherit_id" ref="base.res_partner_kanban_view" />
  <field name="name">res.partner.kanban.names</field>
  <field name="model">res.partner</field>
  <field name="arch" type="xml">
    <data>
      <xpath expr="/kanban/field[1]" position="after">
        <field name="type"/>
      </xpath>
      <xpath expr="/kanban/templates//a[@type='open'][1]/t[2]/t[2]/img" position="replace">
        <a type="open">
          <t t-if="record.has_image.raw_value === true">
            <img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_kanban_image"/>
            <img t-elseif="record.is_company.raw_value === true" t-att-src='_s + "/base/static/src/img/company_image.png"' class="oe_kanban_image"/>
            <img t-elseif="record.type.raw_value === 'contact'" t-att-src='_s + "/base/static/src/img/avatar.png"' class="oe_kanban_image"/>
            <img t-else="" t-att-src='_s + "/base/static/src/img/icon.png"' class="oe_kanban_image"/>
          </t>
        </a>
      </xpath>
      <xpath expr="/kanban/templates//ul" position="replace">
        <ul>
          <li t-if="record.parent_id.raw_value">
            <t t-if="record.function.raw_value"><field name="function"/> <i>at</i> </t><field name="parent_id"/>
            <li t-elseif="record.function.raw_value"><field name="function"/></li>
          </li>
          <li t-if="record.city.raw_value">
            <field name="city"/><t t-if="record.country_id.raw_value">, <field name="country_id"/></t>
            <li t-elseif="record.country_id.raw_value"><field name="country_id"/></li>
          </li>
          <li t-if="record.email.raw_value"><a t-attf-href="mailto:#{record.email.raw_value}"><field name="email"/></a></li>
        </ul>
      </xpath>
    </data>
  </field>
</record>
[/code]

As you can see there are two forms to use this directives:
1.
<div t-if>
  "if-content"
  <div t-elseif/>
  "elseif-content"
  <div t-else/>
  "else-content"
</t-if>

2.
<t t-if>
  <div>"if-content"</div>
  <t t-elseif>
    <div>"elseif-content"</div>
  </t>
  <t t-else>
    <div>"else-content"</div>
  </t>
</t-if>

Both are compiled to something like that
if (cond) {
  r.push('<div>"if content"</div>')
} else if (cond) {
  r.push('<div>"elseif- content"</div>')
} else {
  r.push('<div>"else- content"</div>')
}

It might be confusing for a reviewer if both forms are mixed within one if-elseif-else-compound.
In the second form content between the last closing </t> and the closing </t-if> is appended to the else-content.

Solution 1: Well documentation and responsibility of the developer who designs the view.
Solution 2: QWeb2 raises an exception on malformed usage (first form only for non-t-tags second form only for t-tags; strip whitespaces between <elseif>, <else> and the closing </t>, fail on other content).

If the team likes this extensions and wants me to do this I would would work on solution 2.