<?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="crm-batch-grid" title="CRM batches" model="com.axelor.apps.crm.db.CrmBatch">
		<field name="actionSelect" />
		<field name="code" x-bind="{{code|unaccent|uppercase}}" />
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="createdOn"/>
		<field name="createdBy" form-view="user-form" grid-view="user-grid"/>
	</grid>
 
	<form onLoad="action-crm-batch-attrs-action-select" onNew="action-group-crm-crmbatch-onnew" name="crm-batch-form" title="CRM Batch" model="com.axelor.apps.crm.db.CrmBatch" width="large">
		<panel name="mainPanel" >
		  <field name="actionSelect" onChange="action-crm-batch-attrs-action-select"/>
		  <field name="code" x-bind="{{code|unaccent|uppercase}}" onChange="action-base-batch-condition-check-unique-code"/>
		  <field name="company" canEdit="false" widget="SuggestBox" form-view="company-form" grid-view="company-grid"/>
		</panel>
		<panel-tabs name="mainPanelTab">
		  <panel name="eventReminderPanel" title="Event reminder page">
		    <button name="eventReminderBatchBtn" title="Event reminder batch"   onClick="save,action-crm-batch-method-action-event-reminder"/>
		  </panel>
		  <panel name="targetPanel" title="Target page">
		    <field name="targetConfigurationSet" colSpan="12" form-view="target-configuration-form" grid-view="target-configuration-grid"/>
		    <button name="targetBatchBtn" title="Target batch" colSpan="4" onClick="save,action-crm-batch-method-action-target"/>
		  </panel>
		  <panel name="informationPanel" title="Information" >
		    <field name="createdOn" title="Created on"/>
		    <field name="createdBy" title="Created by" form-view="user-form" grid-view="user-grid"/>
		    <field name="description" colSpan="12" />
		    <panel-related name="batchListPanel" field="batchList" colSpan="12" form-view="batch-form" grid-view="batch-grid" readonly="true"/>
		  </panel>
		</panel-tabs>
	</form>

    
    <action-group name="action-group-crm-crmbatch-onnew">
    	<action name="action-crm-batch-record-on-new"/>
    	<action name="action-crm-batch-attrs-action-select"/>
    </action-group>
    
    <!-- ACTION RECORD -->
    <action-record name="action-crm-batch-record-on-new" model="com.axelor.apps.crm.db.CrmBatch">
		<field name="createdOn" expr="eval:__config__.app.getTodayDate()"/>
		<field name="createdBy" expr="eval:__user__"/>
		<field name="company"  expr="eval:__user__.activeCompany" if="__user__.activeCompany != null"/>
    	<field name="company"  expr="eval:__repo__(Company).all().fetchOne()" if="__user__.activeCompany == null &amp;&amp; __repo__(Company).all().fetch().size == 1"/>
	</action-record>
    
    <!-- ACTION METHOD -->
	<action-method name="action-crm-batch-method-action-event-reminder">
		<call class="com.axelor.apps.crm.web.CrmBatchController" method="actionEventReminder"/>
	</action-method>
	
	<!-- ACTION METHOD -->
	<action-method name="action-crm-batch-method-action-target">
		<call class="com.axelor.apps.crm.web.CrmBatchController" method="actionTarget"/>
	</action-method>
	
    <!-- ACTION ATTRS -->
    <action-attrs name="action-crm-batch-attrs-action-select">
	    <attribute name="hidden" expr="eval: actionSelect != 21" for="eventReminderPanel"/>
	    <attribute name="hidden" expr="eval: actionSelect != 22" for="targetPanel"/>
	</action-attrs>
	
</object-views>