<?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="convert-lead-wizard-form" title="Convert lead" model="com.axelor.apps.base.db.Wizard" width="large" onNew="action-convert-lead-wizard-method-set-defaults" canSave="false">
	  	<toolbar>
		    <button name="validateBtn"  hideIf="!$leadToPartnerSelect || $leadToPartnerSelect == 2 &amp;&amp; $selectPartner == null || $leadToContactSelect == 2 &amp;&amp; $selectContact == null &amp;&amp; $selectPartner.partnerTypeSelect == 1" title="Validate" onClick="action-convert-lead-validate-confirm-validate-lead,action-lead-method-convert-lead"/>
	  	</toolbar>
	  	<panel name="mainPanel" >
	  		<field name="$leadToPartnerSelect" title="Convert lead into partner" required="true" type="integer" selection="crm.convert.lead.wizard.lead.to.partner.select" onChange="action-convert-lead-attrs-lead-to-contact-select-reset"/> 
		    <field name="$selectPartner" showIf="$leadToPartnerSelect == 2" requiredIf="$leadToPartnerSelect == 2" title="Select Partner" widget="ManyToOne" domain="self.isContact = 'false'" form-view="partner-form" grid-view="partner-grid" target="com.axelor.apps.base.db.Partner" />
		    <field name="$leadToContactSelect" showIf="$leadToPartnerSelect == 1  &amp;&amp; $partner.partnerTypeSelect != 2" title="Convert lead into contact" type="integer" selection-in="[1]" selection="crm.convert.lead.wizard.lead.to.contact.select" />
		    <spacer name="leadContactSelectSpacer" showIf="$leadToPartnerSelect == 1"/>
		    <field name="$leadToContactSelect" showIf="$leadToPartnerSelect == 2 &amp;&amp; $selectPartner.partnerTypeSelect != 2" title="Convert lead into contact" type="integer" selection="crm.convert.lead.wizard.lead.to.contact.select" />
		    <field name="$selectContact" showIf="$leadToPartnerSelect == 2 &amp;&amp;  $leadToContactSelect == 2 &amp;&amp; $selectPartner.partnerTypeSelect != 2" requiredIf="$leadToPartnerSelect == 2 &amp;&amp;  $leadToContactSelect == 2" title="Select Contact" widget="ManyToOne" domain="self.isContact = 'true'" form-view="partner-contact-form" grid-view="partner-contact-grid" target="com.axelor.apps.base.db.Partner" />
	 		<field name="$selectPartner.partnerTypeSelect" hidden="true" />
	 	</panel>
		<panel name="convertToPartnerPanel" showIf="$leadToPartnerSelect == 1">
			<field name="$partner" showTitle="false" colSpan="12" canSelect="false" x-show-icons="false" target="com.axelor.apps.base.db.Partner" type="many-to-one">
				<editor x-show-titles="false" onNew="action-convert-lead-wizard-record-default-partner">
					<panel name="imagePanel" colSpan="12">
						<field name="picture" colSpan="2" widget="Image" showTitle="false"/>
					    <field name="partnerTypeSelect" showTitle="false" onChange="action-partner-partner-type-select-change,action-convert-lead-method-set-individual-partner"/>
						<field name="titleSelect"  showTitle="false" hideIf="partnerTypeSelect != 2" placeholder="Civility" colSpan="2"/>
						<field name="name" showTitle="false" css="highlight" placeholder="Name" colSpan="5" onChange="action-group-base-partner-contact-name-onchange"/>
						<field name="firstName" showTitle="false" hideIf="partnerTypeSelect != 2" css="highlight" placeholder="First name" colSpan="5" onChange="action-group-base-partner-contact-name-onchange"/>
					</panel>
					
					<panel name="informationPanel" title="Informations" colSpan="12">
						<field name="isProspect" showTitle="true" colSpan="4"  onChange="action-partner-attrs-unset-customer"/>
		      			<field name="isCustomer" showTitle="true" colSpan="4"  onChange="action-partner-attrs-unset-prospect"/>
		      			<field name="isSupplier" showTitle="true" colSpan="4" />
		      		</panel>
	      			
	      			<panel name="generalContactDetailsPanel" title="General contact details" colSpan="12">
						<field name="fixedPhone" colSpan="3" placeholder="+33100000000" pattern="^\+?([\s()-.]*\d){7,}$" onChange="action-partner-method-normalize-fixedPhone"/>
						<field name="fax" colSpan="3" placeholder="+33000000000" pattern="^\+?([\s()-.]*\d){7,}$" onChange="action-partner-method-normalize-fax"/>
						<field name="mobilePhone" colSpan="3" hideIf="partnerTypeSelect == 1" placeholder="+33100000000" pattern="^\+?([\s()-.]*\d){7,}$" onChange="action-partner-method-normalize-mobilePhone"/>
						<field name="emailAddress" canSelect="false" form-view="email-address-simple-form"/>
						<field name="webSite" placeholder="www.url.com" pattern="([^\s]+\.[^\s]+\.[^\s]{2,})"/>
					</panel>
	      			
	    			<panel name="partnerDetailsPanel" title="Partner Details"  colSpan="12">
				        <field name="partnerCategory" widget="SuggestBox" hideIf="partnerTypeSelect == 2" form-view="partner-category-form" grid-view="partner-category-grid"/>
				        <field name="industrySector" widget="SuggestBox" hideIf="partnerTypeSelect == 2"/>
				        <field name="department" hideIf="partnerTypeSelect == 2" form-view="department-form" grid-view="department-grid"/>
				        <field name="saleTurnover" showTitle="true" hideIf="partnerTypeSelect == 2"/>
				        <field name="nbrEmployees" hideIf="partnerTypeSelect == 2"/>
				        <field name="registrationCode" hideIf="partnerTypeSelect == 2"/>
				        <field name="taxNbr" showTitle="true" hideIf="partnerTypeSelect == 2"/>
		                <field name="source" hidden="true"/>
	                </panel>
	                <panel name="settingsPanel" title="Settings" colSpan="12">
						<field name="language" colSpan="6" canEdit="false"/>
						<panel name="assignedToPanel" title="Assigned to" colSpan="12">
							<field name="user" colSpan="6" form-view="user-form" grid-view="user-grid" hideIf="isEmployee" canNew="false" canEdit="false" canView="false"/>
							<field name="team" canEdit="false" colSpan="6" form-view="team-form" grid-view="team-grid" if="__config__.app.getApp('base').getTeamManagement()" hideIf="isEmployee"/>
						</panel>
					</panel>
	            </editor>
			</field>
			<panel name="addressPanel">
			    <label name="invoicingAddressLabel" title="Invoicing Address" colSpan="12"/>
			    <field name="$primaryAddress" placeholder="Address" showTitle="false" type="string"/>
			    <field name="$primaryCity" placeholder="City" showTitle="false" type="string"/>
			    <field name="$primaryState" placeholder="State" showTitle="false" type="string"/>
			    <field name="$primaryPostalCode" placeholder="Postal code" showTitle="false" type="string"/>
			    <field name="$primaryCountry" placeholder="Country" showTitle="false" widget="ManyToOne" target="com.axelor.apps.base.db.Country" target-name="name"/>
			    <label name="deliveryAddressLabel" title="Delivery Address" colSpan="12"/>
			    <field name="$partner.partnerTypeSelect" hidden="true" />
   			</panel>
		</panel>
		<panel  name="createContactPanel" title="Contact" showIf="$leadToContactSelect == 1 &amp;&amp; ($leadToPartnerSelect == 1 &amp;&amp; $partner.partnerTypeSelect == 1 || $leadToPartnerSelect == 2 &amp;&amp; $selectPartner.partnerTypeSelect != 2)">
			<field name="$contactPartner" showTitle="false" colSpan="12" canSelect="false" x-show-icons="false" form-view="contact-form" target="com.axelor.apps.base.db.Partner" type="many-to-one">
				<editor x-show-titles="false" onNew="action-convert-lead-wizard-record-default-contact" >
					<field name="picture" colSpan="2" widget="Image" showTitle="false"/>
					<field name="titleSelect"  showTitle="false" placeholder="Civility" colSpan="2"/>
					<field name="name" showTitle="false" css="highlight" placeholder="Name" colSpan="4" onChange="action-group-base-partner-contact-name-onchange"/>
					<field name="firstName" showTitle="false" css="highlight" placeholder="First name" colSpan="4" onChange="action-group-base-partner-contact-name-onchange"/>
					<label name="contactLabel" title="Contact"/>
					<field name="jobTitleFunction"/>
					<field name="reportsTo" domain="self.isContact = true"/>
					<field name="fixedPhone"/>
					<field name="mobilePhone"/>
					<field name="emailAddress" canSelect="false" form-view="email-address-simple-form"/>
					<field name="fax"/>
					<field name="user" />
					<field name="team" />
				</editor>
			</field>
			<label name="addressLabel" title="Address"/>
			<field name="$contactAddress" placeholder="Address" showTitle="false" type="string" colSpan="12"/>
			<field name="$contactCity" placeholder="City" showTitle="false" type="string" colSpan="4"/>
			<field name="$contactState" placeholder="State" showTitle="false" type="string" colSpan="4"/>
			<field name="$contactPostalCode" placeholder="Postal code" showTitle="false" type="string" colSpan="4"/>
			<field colSpan="12" name="$contactCountry" placeholder="Country" showTitle="false" widget="ManyToOne" target="com.axelor.apps.base.db.Country" target-name="name"/>
		</panel>
	</form>
	
	<action-validate name="action-convert-lead-validate-confirm-validate-lead">
       <alert message="Are you sure you want to convert the lead?"/>
    </action-validate>
    
    <action-method name="action-convert-lead-wizard-method-set-defaults">
    	<call class="com.axelor.apps.crm.web.ConvertLeadWizardController" method="setDefaults"/>
    </action-method>
    
    <action-method name="action-convert-lead-wizard-record-default-partner">
		<call class="com.axelor.apps.crm.web.ConvertLeadWizardController" method="setPartnerDefaults"/>
	</action-method>
	
	<action-method name="action-convert-lead-wizard-record-default-contact">
		<call class="com.axelor.apps.crm.web.ConvertLeadWizardController" method="setContactDefaults"/>
	</action-method>

    <action-method name="action-lead-method-convert-lead">
		<call class="com.axelor.apps.crm.web.ConvertLeadWizardController" method="convertLead"/>
    </action-method>
    
    <action-method name="action-convert-lead-method-set-individual-partner">
    	<call class="com.axelor.apps.crm.web.ConvertLeadWizardController" method="setIndividualPartner"/>
    </action-method>
    
    <action-attrs name="action-convert-lead-attrs-lead-to-contact-select-reset">
    	<attribute name="value" for="$leadToContactSelect" expr="eval:1"/>
    </action-attrs>
    
</object-views>