<?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="message-form" id="base-message-form" title="Email" model="com.axelor.apps.message.db.Message"
    onNew="action-group-base-message-onnew">
		<toolbar>
	        <button name="printBtn" title="Print" icon="fa-print" onClick="save,action-message-method-print-pdf-email" readonlyIf="id == null"/>
	        <button name="sendBtn" title="Send" icon="fa-envelope" onClick="action-group-message-message-send-click" showIf="statusSelect == 1 " />
        	<button name="trashBtn" title="Delete" icon="fa-trash" onClick="action-group-message-message-delete-click" showIf="statusSelect != 4 "/>
		</toolbar>
    	<panel name="informationsPanel" title="Informations" readonlyIf="statusSelect != 1">
            <field name="mediaTypeSelect" readonlyIf="statusSelect != 1"/>
			<field name="statusSelect"/>
			<field name="senderUser" canNew="false" canEdit="false" canView="false"/>
			<field name="sentDateT" colSpan="4"/>
			<panel name="emailDetailsPanel" colSpan="12" showIf="mediaTypeSelect == 2">
			    <field name="fromEmailAddress" widget="SuggestBox" form-view="email-address-form" grid-view="email-address-grid"/>
				<field name="mailAccount" widget="SuggestBox" onChange="action-message-record-get-signature" onSelect="action-message-attribute-mail-account" requiredIf="mediaTypeSelect == 2"  form-view="mail-account-form" grid-view="mail-account-grid"/>
        		<field name="replyToEmailAddressSet" widget="TagSelect" x-create="address" form-view="email-address-form" colSpan="12" grid-view="email-address-grid"/>			
        	</panel>
       	</panel>
		<panel name="recipientAddressPanel" title="Recipient address" readonlyIf="statusSelect != 1" showIf="mediaTypeSelect == 1">
			<field name="addressBlock" colSpan="12" widget="html" x-lite="false" height="5" showTitle="false" showIf="mediaTypeSelect == 1" requiredIf="mediaTypeSelect == 1"/>
		</panel>
        <panel name="recipientsPanel" title="Recipients" readonlyIf="statusSelect != 1" showIf="mediaTypeSelect == 2">
        	<field name="toEmailAddressSet" widget="TagSelect" x-create="address" form-view="email-address-form" colSpan="12" requiredIf="mediaTypeSelect == 2" grid-view="email-address-grid"/>
        	<field name="ccEmailAddressSet" widget="TagSelect" x-create="address" form-view="email-address-form" colSpan="12" grid-view="email-address-grid"/>
        	<field name="bccEmailAddressSet" widget="TagSelect" x-create="address" form-view="email-address-form" colSpan="12" grid-view="email-address-grid"/>
        </panel>
		<panel name="messageDestinatedToPanel" title="Message destinated to" readonlyIf="statusSelect != 1" showIf="mediaTypeSelect == 3">
			<field name="recipientUser" colSpan="6" showTitle="false" showIf="mediaTypeSelect == 3" requiredIf="mediaTypeSelect == 3" form-view="user-form" grid-view="user-grid" canNew="false" canEdit="false" canView="false"/>
		</panel>
        <panel name="contentPanel" title="Content" readonlyIf="statusSelect != 1">
        	<field name="subject" title="Subject" colSpan="12" required="true"/>
       	 	<field name="content" colSpan="12" showTitle="false" widget="html"/>
        </panel>
        <panel name="relatedToPanel" title="Related to" sidebar="true" colSpan="12" readonlyIf="statusSelect == 4">
			<field name="company" colSpan="12" form-view="company-form" grid-view="company-grid" canEdit="false"/>
			<panel colSpan="12" name="relatedTo1SelectPanel">
				<field name="relatedTo1Select" widget="RefSelect" x-related="relatedTo1SelectId" colSpan="12"/>
			</panel>
			<panel colSpan="12"  name="relatedTo2SelectPanel">
				<field name="relatedTo2Select" widget="RefSelect" x-related="relatedTo2SelectId" colSpan="12" showIf="relatedTo1Select != null"/>
			</panel>
		</panel>
    </form>
    
    <action-group name="action-group-base-message-onnew">
    	<action name="action-message-record-default"/>
    	<action name="action-message-record-mail-account"/>
    	<action name="action-message-record-get-signature"/>
    	<action name="action-message-record-active-company"/>
    	<action name="action-message-record-default-media-type"/>
    </action-group>
    
    <action-attrs name="action-message-attribute-mail-account">
    	<attribute name="domain" for="mailAccount" expr="self.isValid IS TRUE"/>
    	<attribute name="domain" for="mailAccount" expr="self.isValid IS TRUE AND self.user = :__user__" if="eval: __config__.app.getApp('base').getEmailAccountByUser()"/>
    </action-attrs>
	
    <action-record model="com.axelor.apps.message.db.Message" name="action-message-record-active-company">
    	<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 name="action-message-method-print-pdf-email">
		<call class="com.axelor.apps.base.web.MessageController" method="printMessage"/>
	</action-method>
    
</object-views>
