<?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="job-application-grid" title="Job applications" model="com.axelor.apps.talent.db.JobApplication">
		<field name="lastName" />
		<field name="firstName" />
		<field name="emailAddress" />
		<field name="fixedPhone" />
		<field name="mobilePhone" />
		<field name="jobPosition" />
		<field name="statusSelect" />
	</grid>
	
	<form name="job-application-form" title="Job application" model="com.axelor.apps.talent.db.JobApplication" width="large"
		onNew="action-job-application-defaults" onLoad="action-talent-method-set-social-network-url">
		<menubar>
	        <menu name="jobApplicationToolsMenu" title="Tools" icon="fa-wrench" showTitle="true">
	            <item name="scheduleEventItem" title="Schedule Event" action="save,action-job-application-schedule-event" readonlyIf="id == null"/>
	        </menu>
	    </menubar>
		<panel name="mainPanel" readonlyIf="statusSelect == 3">
			<field name="statusSelect" widget="NavSelect" showTitle="false" colSpan="8" readonly="true"/>
			<field name="hiringStage" colSpan="4" widget="SuggestBox" canEdit="false"/>
			<panel name="imagePanel" colSpan="4">
				<field name="picture"  widget="Image" colSpan="12" showTitle="false">
					<viewer>
						<![CDATA[
							<img ng-show="record.picture" ng-src="{{$image('picture', 'content')}}" />
							<img ng-show="!record.picture" src="img/partner-default.png" />
						]]>
					</viewer>
				</field>
			</panel>
			<panel name="namePanel" colSpan="8">
				<field name="titleSelect" selection-in="[1,2]"/>
				<spacer/>
				<field name="firstName" onChange="action-talent-method-set-social-network-url"/>
				<field name="lastName" required="true" onChange="action-talent-method-set-social-network-url"/>
				<field name="employee" showIf="statusSelect == 1" />
			</panel>
		</panel>
		<panel sidebar="true" name="actionsPanel">
			<button name="openBtn" title="Open" onClick="save,action-job-application-status-open,save" colSpan="12" hideIf="statusSelect == 0"/>
			<button name="rejectBtn" title="Rejected" onClick="save,action-job-application-status-reject,save" colSpan="12" showIf="statusSelect == 0"/>
			<button name="hireBtn" title="Hire" onClick="save,action-job-application-confirmation,action-job-application-method-hire" colSpan="12" showIf="statusSelect == 0"/>
			<button name="cancelBtn" title="Cancel" onClick="save,action-job-application-status-cancel,save" colSpan="12" icon="fa-times-circle" css="btn-danger" hideIf="statusSelect == 1 || statusSelect == 3"/>
		</panel>
		<panel sidebar="true" name="JobOfferInformationPanel" title="Job Offer Information" readonlyIf="statusSelect == 3">
			<field name="jobPosition" colSpan="6" canEdit="false"/>
			<field name="jobPosition.statusSelect" colSpan="6"/>
			<field name="responsible" colSpan="6" canEdit="false"/>
			<field name="jobPosition.companyDepartment" colSpan="6"/>
			<field name="jobPosition.publicationDate" colSpan="6"/>
		</panel>
		<panel sidebar="true" name="applicationInformationPanel" title="Application Information" readonlyIf="statusSelect == 3">
			<field name="educationLevel" colSpan="6"/>
			<field name="experienceSelect" colSpan="6"/>
			<field name="industrySectorSet" widget="TagSelect" colSpan="6"/>
			<field name="talentSource" title="Source" colSpan="6"/>
			<field name="skillSet" widget="TagSelect" colSpan="6"/>
			<field name="referredBy" colSpan="6"/>
			<field name="creationDate" colSpan="6"/>
			<field name="appreciation" widget="SelectProgress" colSpan="6"/>
		</panel>

		<panel-tabs name="mainPanelTab" readonlyIf="statusSelect == 3">
			<panel name="descriptionPanel" title="Description">
				<field name="description" widget="html" colSpan="12" />
			</panel>
			<panel name="contactPanel" title="Contact" colSpan="12">
				<panel name="contactDetailsPanel" title="Contact details" colSpan="12">
					<field name="mobilePhone" colSpan="3"/>
					<field name="emailAddress" canRemove="false" canSelect="false" canSuggest="false" colSpan="3" canNew="true" canEdit="true">
            <editor x-show-titles="false">
              <field name="address" colSpan="12" pattern="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@+[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$" widget="Email" placeholder="user@mydomain.com"/>
            </editor>
					</field>
					<field name="fixedPhone" colSpan="3"/>
					<field name="fax" colSpan="3"/>
					<field name="linkedInProfile" colSpan="3" widget="url"/>
					<label name="linkedinLabel" title="&lt;a class='fa fa-linkedin' href='http://www.linkedin.com' target='_blank' /&gt;" colSpan="2"/>
				</panel>
				<panel name="primaryAddressPanel" title="Primary Address" colSpan="12">
					<field name="employeeAddress" colSpan="12" form-view="address-form" grid-view="address-grid" canNew="true" canEdit="false"/>
				</panel>
				<field name="fullName" hidden="true" />
			</panel>
			<panel name="contractPanel" title="Contract" colSpan="12">
				<field name="jobPosition.contractType" />
				<field name="expectedSalary" />
				<field name="proposedSalary" />
				<field name="availabilityFrom" />
			</panel>
			<panel-dashlet name="eventsPanel" title="Events" action="action-job-application-events" colSpan="12" />
			<panel name="reasonNotHiredPanel" title="Reason not hired">
				<field name="reasonNotHired" colSpan="12" showTitle="false"/>
			</panel>
		</panel-tabs>

		<panel-mail name="mailPanel">
		  <mail-messages limit="4" />
		  <mail-followers />
	    </panel-mail>
	</form>
	
    <action-view name="action-job-application-schedule-event" title="Schedule Event" model="com.axelor.apps.crm.db.Event">
    	<view type="form" name="event-form"/>
    	<context name="_relatedToSelect" expr="eval:'com.axelor.apps.talent.db.JobApplication'" />
    	<context name="_relatedToSelectId" expr="eval:id" />
    </action-view>
    
    <action-view name="action-job-application-events" model="com.axelor.apps.crm.db.Event" title="Events">
    	<view type="grid" name="event-grid"/>
    	<view type="form" name="event-form"/>
    	<domain>self.relatedToSelect = 'com.axelor.apps.talent.db.JobApplication' and self.relatedToSelectId = :id</domain>
    </action-view>
    
    <action-record name="action-job-application-defaults" model="com.axelor.apps.talent.db.JobApplication">
    	<field name="jobPosition" expr="eval:__repo__(JobPosition).find(_jobPositionId)"/>
    	<field name="responsible" expr="eval:__repo__(Employee).find(_responsibleId)" />
    </action-record>
    
    <action-method name="action-job-application-method-hire">
    	<call class="com.axelor.apps.talent.web.JobApplicationController" method="hire"/>
    </action-method>
    
    <action-attrs name="action-job-application-status-cancel">
    	<attribute name="value" for="statusSelect" expr="eval: 3"/>
    </action-attrs>

    <action-attrs name="action-job-application-status-open">
      <attribute name="value" for="statusSelect" expr="eval: 0"/>
    </action-attrs>

    <action-attrs name="action-job-application-status-reject">
      <attribute name="value" for="statusSelect" expr="eval: 2"/>
    </action-attrs>

    <action-validate name="action-job-application-confirmation">
    	<alert message="A new employee form will be created. Do you confirm the creation ?"/>
    </action-validate>
    
    <action-method name="action-talent-method-set-social-network-url">
    	<call class="com.axelor.apps.talent.web.JobApplicationController" method="setSocialNetworkUrl"/>
    </action-method>
    
    <search-filters name="job-application-filters" model="com.axelor.apps.talent.db.JobApplication" title="Job Application Filters">
		<filter title="Current applications">
			<domain>self.statusSelect = 0</domain>
		</filter>
	</search-filters>
	
</object-views>
