<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<object-views xmlns="http://axelor.com/xml/ns/object-views"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://axelor.com/xml/ns/object-views http://axelor.com/xml/ns/object-views/object-views_5.2.xsd">
    
    <grid name="querie-grid" title="Queries" model="com.axelor.apps.base.db.Querie">
    	<field name="name"/>
        <field name="type"/>
        <field name="metaModel" form-view="meta-model-form" grid-view="meta-model-grid"/>
    </grid>
    
    <form name="querie-form" title="Querie" model="com.axelor.apps.base.db.Querie" 
    	onNew="action-querie-record-new">
    	<panel name="mainPanel">
	        <field name="name"/>
	        <field name="metaModel" form-view="meta-model-form" grid-view="meta-model-grid"/>
	        <field name="type"/>
	        <field name="query" widget="CodeEditor" x-syntax="sql" hideIf="type == 3" colSpan="12"/>
	        <button name="checkQueryBtn" title="Check query" onClick="action-querie-check-query"/>
        </panel>
    </form>
    
    <action-record name="action-querie-record-new" model="com.axelor.apps.base.db.Querie">
    	<field name="metaModel" expr="eval: _parent?.metaModel" if="_parent?.metaModel"/>
    	<field name="metaModel" expr="eval: _parent?.targetSelect == 1 ? __repo__(MetaModel).all().filter('self.name = \'Partner\'').fetchOne() : (_parent?.targetSelect == 2 ? __repo__(MetaModel).all().filter('self.name = \'Lead\'').fetchOne() : null)" if="_parent?.targetSelect"/>
    </action-record>
    
    <action-method name="action-querie-check-query">
    	<call class="com.axelor.apps.base.web.QuerieController" method="checkQuerie"/>
    </action-method>
    
</object-views>
