<?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="chart-builder-filter-grid" title="Filters" model="com.axelor.studio.db.Filter" onNew="action-filter-line-defaults">
      <field name="logicOp" />
      <field name="isJson" />
      <field name="metaJsonField" readonlyIf="!isJson"  requiredIf="isJson" widget="SuggestBox" onSelect="action-chart-filter-meta-json-field-domain" onChange="action-filter-method-update-target-field" />
      <field name="metaField" readonlyIf="isJson" requiredIf="!isJson" widget="SuggestBox" onChange="action-filter-method-update-target-field" onSelect="action-chart-filter-meta-field-domain"/>
      <field name="targetField" onChange="action-filter-method-update-target-type" readonlyIf="!isJson &amp;&amp; metaField.relationship == null || isJson &amp;&amp; metaJsonField.targetModel == null &amp;&amp; metaJsonField.targetJsonModel == null" requiredIf="!isJson &amp;&amp; metaField.relationship != null || isJson &amp;&amp; metaJsonField.targetModel != null"  />
      <field name="operator"/>
      <field name="value" readonlyIf="isParameter" onChange="action-studio-filter-validate-values"/>
      <field name="isParameter" />
      <field name="defaultValue" readonlyIf="!isParameter"/>
      <field name="targetType" hidden="true" />
      <field name="metaField.relationship" hidden="true" />
      <field name="metaJsonField.targetModel" hidden="true" />
      <field name="metaJsonField.targetJsonModel" hidden="true" />
      <field name="metaJsonField.type" hidden="true" />
      <field name="isTargetJson" hidden="true" />
  </grid>
  
  <action-method name="action-filter-method-update-target-field">
  	<call class="com.axelor.studio.web.FilterController" method="updateTargetField" />
  </action-method>
  
  <action-method name="action-filter-method-update-target-type">
  	<call class="com.axelor.studio.web.FilterController" method="updateTargetType" />
  </action-method>
  
  <action-method name="action-filter-method-update-target-meta-field">
    <call method="updateTargetMetaField" class="com.axelor.studio.web.FilterController"/>
  </action-method>

  <action-method name="action-filter-method-clear-selection">
    <call method="clearSelection" class="com.axelor.studio.web.FilterController"/>
  </action-method>

  <action-attrs name="action-chart-filter-meta-json-field-domain">
  	<attribute for="metaJsonField" name="domain" expr="eval:&quot;self.jsonModel.name = '${_parent.model}' AND (self.type != 'json-one-to-many' OR self.type != 'one-to-many' OR self.type != 'many-to-many' OR self.type != 'json-many-to-many')&quot;"/>
  </action-attrs>
  
  <action-attrs name="action-filter-line-defaults">
  	<attribute name="value" for="isJson" expr="eval:_parent?.isJson" />
  </action-attrs>
  
  <action-attrs name="action-chart-filter-meta-field-domain">
      <attribute for="metaField" name="domain" expr="eval:&quot;self.metaModel.fullName = '${_parent.model}' AND (self.relationship IS NULL OR self.relationship != 'OneToMany' OR self.relationship != 'ManyToMany')&quot;"/>
  </action-attrs>
  
  <action-validate name="action-studio-filter-validate-values">
  	<error message="Please input value bind with single quotation."  action="action-studio-filter-reset-value" 
  	if="value != null &amp;&amp; targetType != null &amp;&amp; !['$user','$date','$time'].contains(value) &amp;&amp; (!value.startsWith(&quot;'&quot;) || !value.endsWith(&quot;'&quot;)) &amp;&amp; (targetType.toLowerCase().contains('string') || targetType.toLowerCase().contains('date'))"/>
  </action-validate>
  
  <action-attrs name="action-studio-filter-reset-value">
  	<attribute name="value" for="value" expr="eval:null"/>
  </action-attrs>
  
</object-views>