<?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="extra-hours-grid" title="Extra Hours" model="com.axelor.apps.hr.db.ExtraHours" canNew="false" orderBy="-sentDate">
		<hilite color="danger" if="statusSelect == 4"/>
		<hilite color="success" if="statusSelect == 3"/>
		<hilite color="warning" if="statusSelect == 2"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="sentDate"/>
		<field name="statusSelect"/>
		<field name="user" form-view="user-form" grid-view="user-grid"/>
	</grid>
	
	<grid name="extra-hours-validate-grid" title="Extra Hours" model="com.axelor.apps.hr.db.ExtraHours" canNew="false" orderBy="-sentDate">
		<toolbar>
			<button name="showSubordinateExtraHoursToValidateBtn" title="Show extra hours to be validated by my subordinates" onClick="com.axelor.apps.hr.web.extra.hours.ExtraHoursController:showSubordinateExtraHours"/>
		</toolbar>
		<hilite background="danger" if="$moment(sentDate).diff(todayDate,'days') &lt;= 0"/>
		<hilite background="warning" if="$moment(todayDate).diff(sentDate,'days') &gt;= 7"/>
		<field name="company" form-view="company-form" grid-view="company-grid" if="__config__.app.getApp('base').getEnableMultiCompany()"/>
		<field name="sentDate"/>
		<field name="statusSelect"/>
		<field name="user" form-view="user-form" grid-view="user-grid"/>
	</grid>

	<form name="extra-hours-form" title="Extra Hours" model="com.axelor.apps.hr.db.ExtraHours" cols="12" width="large"
	    onNew="action-group-extra-hours-onnew"
	    onLoad="action-extra-hours-attrs-buttons,action-extra-hours-attrs-title-project" canNew="false" canCopy="false">
		<panel name="mainPanel">
			<panel colSpan="9" name="statusPanel">
				<field name="statusSelect" colSpan="12" widget="NavSelect" showTitle="false"/>
			</panel>
			<panel name="actionsPanel" itemSpan="12" colSpan="3">
				<button name="confirmBtn" onClick="action-extra-hours-group-confirm" title="Confirm" hideIf="statusSelect &gt; 1" icon="fa-check-square-o"/>
				<button name="validateBtn" hidden="true" onClick="action-extra-hours-group-validate" title="Validate"/>
				<button name="refuseBtn" hidden="true" onClick="action-extra-hours-group-refuse" title="Refuse"/>
				<button name="cancelBtn" onClick="action-extra-hours-method-cancel,save,action-extra-hours-attrs-buttons" hideIf="statusSelect == 5" title="Cancel" icon="fa-times-circle" css="btn-danger"/>
				<button name="draftBtn" onClick="action-extra-hours-record-draft,save,action-extra-hours-attrs-buttons" title="Return to draft status" showIf="statusSelect &gt; 3 "/>
			</panel>
		</panel>
		<panel name="headPanel">
			<field name="sentDate" colSpan="3"/>
			<field name="totalQty" colSpan="3"/>
			<field name="company" canEdit="false" colSpan="3" form-view="company-form" grid-view="company-grid"/>
			<field name="user" colSpan="3" form-view="user-form" grid-view="user-grid" canNew="false" canEdit="false" canView="false"/>
		</panel>
		<panel-related name="extraHoursLineListPanel" field="extraHoursLineList" onChange="action-extra-hours-method-compute"/>
		<panel name="validationPanel">
			<field name="validatedBy" canEdit="false" form-view="user-form" grid-view="user-grid"/>
			<field name="refusedBy" canEdit="false" form-view="user-form" grid-view="user-grid"/>
			<field name="validationDate"/>
			<field name="refusalDate"/>
			<field name="groundForRefusal" showIf="statusSelect == 4" colSpan="12"/>
		</panel>
		<panel-mail name="mailPanel">
		  <mail-messages limit="4" />
		  <mail-followers />
	    </panel-mail>
	</form>
	
	<form name="popup-extra-hours-refusal-form" title="Ground for refusal" model="com.axelor.apps.hr.db.ExtraHours">
		<field name="groundForRefusal" showTitle="false"/>
	</form>
	
	<form name="popup-extra-hours-form" title="Select the extra hours you want to edit" model="com.axelor.apps.base.db.Wizard" onNew="action-extra-hours-attrs-domain-extra-hours-select">
		<field name="$extraHoursSelect" title="Select extra hours" type="many-to-one" target="com.axelor.apps.hr.db.ExtraHours" widget="SuggestBox" />
		<button name="editExtraHoursSelectedBtn" title="Edit extra hours selected" onClick="com.axelor.apps.hr.web.extra.hours.ExtraHoursController:editExtraHoursSelected,close"/>
	</form>
	
	<action-group name="action-group-extra-hours-onnew">
		<action name="action-extra-hours-record-default"/>
		<action name="action-extra-hours-attrs-buttons"/>
		<action name="action-extra-hours-attrs-title-project"/>
	</action-group>

	<action-group name="action-extra-hours-group-confirm">
		<action name="save"/>
		<action name="action-extra-hours-method-confirm"/>
		<action name="action-extra-hours-attrs-buttons"/>
		<action name="save"/>
	</action-group>
	
	<action-group name="action-extra-hours-group-validate">
		<action name="action-extra-hours-method-valid"/>
		<action name="action-extra-hours-attrs-buttons"/>
		<action name="save"/>
	</action-group>
	
	<action-group name="action-extra-hours-group-refuse">
		<action name="action-extra-hours-method-refuse"/>
		<action name="save"/>
		<action name="action-extra-hours-refusal-popup-form"/>
		<action name="action-extra-hours-attrs-buttons"/>
		<action name="save"/>
	</action-group>
	
	<action-record name="action-extra-hours-record-default" model="com.axelor.apps.hr.db.ExtraHours">
	    <field name="user" expr="eval:__user__"/>
	    <field name="company" expr="eval: __user__.employee?.mainEmploymentContract?.payCompany ?: __user__.activeCompany"/>
	</action-record>
	
	<action-record name="action-extra-hours-record-draft" model="com.axelor.apps.hr.db.ExtraHours">
	    <field name="statusSelect" expr="1"/>
	</action-record>
	
	<action-attrs name="action-extra-hours-attrs-buttons">
		<attribute name="hidden" for="validateBtn" expr="eval: !(statusSelect == 2 &amp;&amp; (__user__ == user?.employee?.managerUser || (__user__ == user &amp;&amp; user?.employee?.managerUser == null) || __user__.employee?.hrManager))"/>
		<attribute name="hidden" for="refuseBtn" expr="eval: !(statusSelect == 2 &amp;&amp; (__user__ == user?.employee?.managerUser || (__user__ == user &amp;&amp; user?.employee?.managerUser == null) || __user__.employee?.hrManager))"/>
		<attribute name="readonly" for="headPanel" expr="eval: (statusSelect == 2 &amp;&amp; !(__user__ == user?.employee?.managerUser || (__user__ == user &amp;&amp; user?.employee?.managerUser == null) || __user__.employee?.hrManager)) || statusSelect &gt; 2"/>
	</action-attrs>
	
	<action-attrs name="action-extra-hours-attrs-title-project">
		<attribute name="title" for="extraHoursLineList.project" expr="eval: __config__.app.getApp('project').getProjectLabel()" if="__config__.app.isApp('project') &amp;&amp; !com.google.common.base.Strings.isNullOrEmpty(__config__.app.getApp('project').getProjectLabel())"/>
	</action-attrs>
	
	<action-attrs name="action-extra-hours-attrs-domain-extra-hours-select">
		<attribute name="domain" for="$extraHoursSelect" expr="eval: &quot; self.statusSelect = 1 AND self.user = ${__user__.id} &quot;"/>
	</action-attrs>
	
	<action-method name="action-extra-hours-method-confirm">
		<call class="com.axelor.apps.hr.web.extra.hours.ExtraHoursController" method="confirm"/>
	</action-method>
	
	<action-method name="action-extra-hours-method-valid">
		<call class="com.axelor.apps.hr.web.extra.hours.ExtraHoursController" method="valid"/>
	</action-method>
	
	<action-method name="action-extra-hours-method-refuse">
		<call class="com.axelor.apps.hr.web.extra.hours.ExtraHoursController" method="refuse"/>
	</action-method>
	
	<action-method name="action-extra-hours-method-cancel">
	    <call class="com.axelor.apps.hr.web.extra.hours.ExtraHoursController" method="cancel"/>
	</action-method>

	<action-method name="action-extra-hours-method-compute">
		<call class="com.axelor.apps.hr.web.extra.hours.ExtraHoursController" method="compute"/>
	</action-method>

	<action-view name="action-extra-hours-refusal-popup-form" title="Ground for refusal" model="com.axelor.apps.hr.db.ExtraHours">
    	<view type="form" name="popup-extra-hours-refusal-form"/>
        <view-param name="popup" value="reload"/>
        <view-param name="show-toolbar" value="false"/>
  		<view-param name="show-confirm" value="true" />
	  	<view-param name="popup-save" value="true"/>
	  	<view-param name="forceEdit" value="true" />
    	<context name="_showRecord" expr="eval: id"/>
    </action-view>
	
</object-views>
