<?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">
	
	<form name="sale-json-field-form" onLoad="action-configurator-json-field-onload" title="Custom field" model="com.axelor.meta.db.MetaJsonField" onNew="action-configurator-set-json-field-default">
	    <panel name="overviewPanel" title="Overview">
	      <field name="$simpleName" onChange="action-configurator-json-field-record-name" title="Name" x-pattern="[a-z][a-zA-Z0-9_\\$]+"/>
		  <field readonly="true" name="name" title="Name to use in scripts"/>
	      <field name="type" selection-in="['string', 'integer', 'decimal', 'boolean', 'datetime', 'date', 'time', 'panel', 'enum', 'button', 'separator', 'many-to-one', 'many-to-many', 'json-many-to-one', 'json-many-to-many']"/>
	      <field name="title" />
	      <field name="defaultValue" />
	      <field name="help" />
	      <field name="sequence" />
	      <field name="model" hidden="true" />
	      <field name="modelField" hidden="true" />
	    </panel>
		<panel-tabs name="mainPanelTab">
			<panel name="optionsPanel" title="Options">
				<panel name="selectTypePanel" itemSpan="12">
					<field name="enumType" showIf="type === 'enum'" widget="ref-text"
						   x-target="com.axelor.meta.db.MetaEnum"
						   x-target-name="name"/>
					<field name="selection" showIf="type !== 'enum'" widget="ref-text"
						   x-target="com.axelor.meta.db.MetaSelect"
						   x-target-name="name" />
				</panel>
				<field name="widget" widget="widget-select" />
				<field name="$showedOnChange" type="string" hideIf="type === 'button'" onChange="action-configurator-record-meta-on-change" title="On change" colSpan="12"/>
				<field name="onChange" hidden="true" colSpan="12"/>
				<field name="onClick" colSpan="12" showIf="type === 'button'" requiredIf="type === 'button'"/>
				<field name="minSize" title="Min" showIf="type.match('string|integer|decimal')" />
				<field name="maxSize" title="Max" showIf="type.match('string|integer|decimal')" />
				<field name="precision" showIf="type === 'decimal'" />
				<field name="scale" showIf="type === 'decimal'" />
				<field name="regex" showIf="type === 'string'" colSpan="12" />
				<panel name="targetModelPanel" itemSpan="12">
					<field name="targetModel" showIf="type.match('^(one|many)-to-')" widget="ref-text"
						   x-target="com.axelor.meta.db.MetaModel"
						   x-target-name="fullName" />
					<field name="targetJsonModel" showIf="type.match('^json-')"
						   title="Target custom model"
						   canEdit="false" canView="false" />
				</panel>
				<field name="domain" showIf="type.match('-to-')" />
				<field name="gridView" showIf="type.match('^(one|many)-to-')" widget="ref-text"
					   x-target="com.axelor.meta.db.MetaView"
					   x-target-name="name"
					   x-domain="self.model = :targetModel AND self.type = 'grid'"/>
				<field name="formView" showIf="type.match('^(one|many)-to-')" widget="ref-text"
					   x-target="com.axelor.meta.db.MetaView"
					   x-target-name="name"
					   x-domain="self.model = :targetModel AND self.type = 'form'"/>
			</panel>
			<panel name="conditionsPanel" title="Conditions" itemSpan="12">
				<field name="contextField" hidden="true" title="Only if" colSpan="6"
					   widget="ref-text"
					   x-target-name="name"
					   x-target="com.axelor.meta.db.MetaField"
					   x-domain="self.name not in ('createdBy', 'updatedBy') and self.relationship = 'ManyToOne' and self.metaModel.fullName = :model"
					   onChange="com.axelor.meta.web.MetaController:contextFieldChange"/>
				<field name="contextFieldValue" hidden="true" colSpan="6" title="Value"
					   widget="EvalRefSelect"
					   x-eval-target="record.contextFieldTarget"
					   x-eval-target-name="record.contextFieldTargetName"
					   x-eval-value="record.contextFieldValue"
					   x-eval-title="record.contextFieldTitle" />
				<field name="contextFieldTitle" hidden="true" />
				<field name="contextFieldTarget" hidden="true" />
				<field name="contextFieldTargetName" hidden="true" />
				<field name="showIf" />
				<field name="hideIf" />
				<field name="requiredIf" />
			</panel>
		</panel-tabs>
		<panel name="attrOptionsPanel" title="Options" sidebar="true" itemSpan="6">
			<field name="required" widget="inline-checkbox" />
			<field name="nameField" widget="inline-checkbox" showIf="type === 'string'" />
			<field name="hidden" widget="inline-checkbox" />
			<field name="visibleInGrid" widget="inline-checkbox" />
		</panel>
		<panel name="widgetAttributesPanel" title="Widget Attributes" sidebar="true">
			<field name="widgetAttrs" widget="json-raw" />
		</panel>
    </form>
    
	<grid name="sale-json-field-grid" title="Custom fields" model="com.axelor.meta.db.MetaJsonField" edit-icon="true">
	  <field name="name"/>
	  <field name="title"/>
	  <field name="type"/>
	</grid>
	
	<action-attrs name="action-configurator-set-json-field-default" >
    	<attribute name="value"	for="model" expr="eval:'com.axelor.apps.sale.db.Configurator'" if="_parent._model == 'com.axelor.apps.sale.db.ConfiguratorCreator'"/>
    	<attribute name="value" for="modelField" expr="eval:'attributes'" if="_parent._model == 'com.axelor.apps.sale.db.ConfiguratorCreator'"/>
<!--     	<attribute name="value" for="showIf" expr="eval:'configuratorCreator?.id == ' + id" if="_parent.model == 'com.axelor.apps.production.db.ConfiguratorCreator'"/> -->
    </action-attrs>

	<action-attrs name="action-configurator-json-field-onload">
		<attribute name="value" for="$simpleName" expr="eval: name.substring(0, name.indexOf('_'))" if="_parent._model == 'com.axelor.apps.sale.db.ConfiguratorCreator'"/>
		<attribute name="value" for="$showedOnChange" expr="eval: onChange.substring(0, onChange.indexOf(','))"
				   if="_parent._model == 'com.axelor.apps.sale.db.ConfiguratorCreator' &amp;&amp; onChange &amp;&amp; onChange != '' &amp;&amp; onChange != 'save,action-configurator-update-indicators,save'"/>
	</action-attrs>

	<action-record name="action-configurator-json-field-record-name" model="com.axelor.meta.db.MetaJsonField">
		<field name="name" expr="eval: simpleName + '_' + __parent__.id"/>
	</action-record>

	<action-record name="action-configurator-record-meta-on-change" model="com.axelor.meta.db.MetaJsonField">
		<field name="onChange" if="showedOnChange &amp;&amp; showedOnChange != ''" expr="eval: showedOnChange + ',save, action-configurator-update-indicators,save' "/>
	</action-record>
    
</object-views>