<?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="mail-account-grid" title="Mail accounts" model="com.axelor.apps.message.db.EmailAccount">
        <field name="name"/>
        <field name="login"/>
        <field name="host"/>
        <field name="isDefault"/>
    </grid>
    
    <form name="mail-account-form" title="Mail account" model="com.axelor.apps.message.db.EmailAccount"
    	onSave="action-mail-account-method-check-default-mail-account">
    	<panel name="informationsPanel" title="Informations">
            <field name="name"/>
			<field name="isDefault" onChange="action-mail-account-method-check-default-mail-account"/>
        	<field name="signature" widget="Html" x-lite="true" height="7" colSpan="12"/>
        </panel>
        <panel name="configPanel" title="Configurations" readonlyIf="isValid">
        	<field name="serverTypeSelect" onChange="action-mail-account-onchange-security-select"/>
        	<field name="host"/>
        	<field name="securitySelect" onChange="action-mail-account-onchange-security-select"/>
        	<field name="port"/>
        </panel>
        <panel name="loginPanel" title="Login" readonlyIf="isValid" >
       	 	<field name="login"/>
        	<field name="password" widget="password"/>
        </panel>
		<panel name="actionsPanel" sidebar="true">
			<field name="isValid" readonly="true"/>
			<button name="testConnectionBtn" onClick="save,action-method-mail-account-validate,save" title="Test connection"/>
			<spacer name="btnSpacer"/>
			<button name="fetchEmailsBtn" onClick="save,action-mail-account-metho-fetch-emails" title="Fetch emails" showIf="isValid &amp;&amp; serverTypeSelect != null &amp;&amp; serverTypeSelect &gt; 1"/>
		</panel>
    </form>
    
	<action-method name="action-method-mail-account-validate">
		<call class="com.axelor.apps.message.web.MailAccountController" method="validateSmtpAccount"/>
	</action-method>
    
	<action-method name="action-mail-account-method-check-default-mail-account">
		<call class="com.axelor.apps.message.web.MailAccountController" method="checkDefaultMailAccount"/>
	</action-method>
	
	<action-method name="action-mail-account-metho-fetch-emails">
		<call class="com.axelor.apps.message.web.MailAccountController" method="fetchEmails"/>
	</action-method>

	<action-method name="action-method-mail-account-validate-password">
		<call class="com.axelor.apps.message.web.MailAccountController" method="validate"/>
	</action-method>

	<action-attrs name="action-mail-account-onchange-security-select" model="com.axelor.apps.message.db.EmailAccount">
		<attribute for="port" name="value" expr="#{securitySelect == 1 ? 465 : securitySelect == 2 ? 587 : 25}" if="serverTypeSelect == 1"/>
		<attribute for="port" name="value" expr="#{securitySelect == 1 ? 995 : 110}" if="serverTypeSelect == 2"/>
		<attribute for="port" name="value" expr="#{securitySelect == 1 ? 993 : 143}" if="serverTypeSelect == 3"/>
	</action-attrs>
	
    
</object-views>
